<%@page language="java" import="com.scalar.chiptrack.finance.purchaseorder.PurchaseOrder,
                                com.scalar.chiptrack.utils.StringUtils,
                                java.util.ArrayList,
                                java.util.Iterator,
                                org.apache.struts.util.LabelValueBean,
                                com.scalar.chiptrack.users.Functionality,
                                com.scalar.chiptrack.users.User,
                                com.scalar.chiptrack.finance.purchaseorder.PurchaseOrderLineItem,
                                com.scalar.chiptrack.finance.purchaseorder.PurchaseOrderLineItemList,
                                com.scalar.chiptrack.sales.receivables.CustomerAddress,
                                com.scalar.chiptrack.sales.receivables.CustomerAddressList,
                                com.scalar.chiptrack.commons.SessionKeys" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>

<%@ page import="com.scalar.chiptrack.utils.ConfigManager"%>

<% int i = 0; /*variable used to assign numers to marketing part number drop down*/ %>

<%
    boolean enableOrDisable = false;
    if( request.getAttribute("enableOrDisable") != null)
    {
        String temp = (String) request.getAttribute("enableOrDisable");
        Boolean tempBoolean = new Boolean(temp);
        enableOrDisable = tempBoolean.booleanValue();
    }
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html:html>
<HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>

<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>

<chiptrack:checkLogon sourcePage="purchaseOrder.do"/>

<META http-equiv='Content-Type' content='text/html; charset=windows-1252'>
<LINK href='<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css' type='text/css' rel='stylesheet'>

<SCRIPT language="JavaScript" src="<%=chipTracContext%>/jsp/includes/scripts/validations.js">
</SCRIPT>

<SCRIPT language='JavaScript'>

var keys                = new Array();
var comments            = new Array();
var vendorPartNumber    = new Array();
var item                = new Array();
var unitCostValue       = new Array();
// Added for Tax Calculations.
var scheduleIdKeys      = new Array();
var scheduleIdValues    = new Array();

var taxOptionKeys       = new Array();
var taxOptionValues     = new Array();

var mfgPartNoKeys       = new Array();
var mfgPartNoValues     = new Array();

// Added for Drop-Ship
var customerIdsArray            = new Array();
var customerAddressesArray      = new Array();
var customerContactPersonArray  = new Array();
var customerAddress1Array       = new Array();
var customerAddress2Array       = new Array();
var customerAddress3Array       = new Array();
var customerCityArray           = new Array();
var customerStateArray          = new Array();
var customerCountryArray        = new Array();
var customerZipCodeArray        = new Array();

function reset()
{

    if( document.purchaseOrderForm['purchaseOrder.poStatus'] != null )
    {
        if ( document.purchaseOrderForm['purchaseOrder.poNumber'].value.length == 0 || document.purchaseOrderForm['purchaseOrder.poStatus'].value == '4' || document.purchaseOrderForm['purchaseOrder.poStatus'].value == '5' )
        {
            return;
        }
    }

    if ( document.purchaseOrderForm['purchaseOrder.poNumber'].value.length > 0 )
    {
        var form = document.purchaseOrderForm;
        document.purchaseOrderForm.reset();
        if( document.purchaseOrderForm['purchaseOrder.poStatus'] != null )
        {
            form['purchaseOrder.poStatus'].disabled = true;    //added 25/04/2004
        }

        if ( form['purchaseOrder.poTypeId'].value == '2' )
        {
           loadCustomerAddresses();
           form['purchaseOrder.shippToAddressId'].value = form.displayShppAddId.value;
           form['purchaseOrder.shippToAddressId'].disabled = false;
           form['purchaseOrder.customerId'].disabled = false;
        }
        else
        {
           form['purchaseOrder.shippToAddressId'].disabled = true;
           form['purchaseOrder.customerId'].disabled = true;
        }
        formatAmountsOnLoad();
        hold ();
    }
}

function enableFields()
{
    var form = document.purchaseOrderForm;
    var count = document.purchaseOrderForm.count.value;
    var selectedStatus;

    // PO related Fields
    form['purchaseOrder.poNumber'].disabled=false;
    form['purchaseOrder.vendorId'].disabled=false;
    form['purchaseOrder.poDate'].disabled = false;
    form['purchaseOrder.requistionDate'].disabled = false;
    form['purchaseOrder.requiredDate'].disabled = false;
    form['purchaseOrder.promisedDate'].disabled = false;
    form['purchaseOrder.promisedShipDate'].disabled = false;
    form['purchaseOrder.poTypeId'].disabled = false;
    form['purchaseOrder.subTotal'].disabled = false;
    form['purchaseOrder.tradeDiscount'].disabled = false;
    form['purchaseOrder.freight'].disabled = false;
    //form['purchaseOrder.remainingPoSubTotal'].disabled = false;
    form['purchaseOrder.commentDescription'].disabled = false;
    form['purchaseOrder.miscellaneous'].disabled = false;
    form['purchaseOrder.tax'].disabled = false;
    form['purchaseOrder.total'].disabled = false;
    if ( form['purchaseOrder.poTypeId'].value == '2' )
    {
        form['purchaseOrder.customerId'].disabled = false;
        form['purchaseOrder.shippToAddressId'].disabled = false;
    }


    // Po Lineitem related Fields
    for( i = 0; i < count; i++ )
    {
        form['purchaseOrder.purchaseOrderLineItemList[' + i + '].marketingPartNo'].disabled = false;
        form['purchaseOrder.purchaseOrderLineItemList[' + i + '].manufacturingPartNo'].disabled = false;
        form['purchaseOrder.purchaseOrderLineItemList[' + i + '].lineItemDescription'].disabled = false;
        //form['purchaseOrder.purchaseOrderLineItemList[' + i + '].siteId'].disabled = false;
        form['purchaseOrder.purchaseOrderLineItemList[' + i + '].requestedQuantity'].disabled = false;
        form['purchaseOrder.purchaseOrderLineItemList[' + i + '].quantityCancelled'].disabled = false;
        form['purchaseOrder.purchaseOrderLineItemList[' + i + '].unitCost'].disabled = false;
        form['purchaseOrder.purchaseOrderLineItemList[' + i + '].extendedCost'].disabled = false;
        //form['purchaseOrder.purchaseOrderLineItemList[' + i + '].poLineItemStatus'].disabled = false; //commented by phani 26/03/2004

        // This is to Assign the Status labels to the Hidden filed to pass it to the Confirm PO page.
        selectedStatus = form['purchaseOrder.purchaseOrderLineItemList[' + i + '].poLineItemStatus'].selectedIndex;
        form['purchaseOrder.purchaseOrderLineItemList[' + i + '].poLineItemStatusLabel'].value = form['purchaseOrder.purchaseOrderLineItemList[' + i + '].poLineItemStatus'].options[selectedStatus].innerText;
    }
}

function addLineItem()
{
    if( document.purchaseOrderForm['purchaseOrder.poStatus'] != null )
    {
        if ( document.purchaseOrderForm['purchaseOrder.poNumber'].value.length == 0 || document.purchaseOrderForm['purchaseOrder.poStatus'].value == '4' || document.purchaseOrderForm['purchaseOrder.poStatus'].value == '5' )
        {
            return;
        }
    }
    if ( document.purchaseOrderForm['purchaseOrder.poNumber'].value.length > 0 )
    {
        var form = document.purchaseOrderForm;
        if( typeof form['purchaseOrder.poHold'] == "undefined" )
        {
            calculateTotal();
            if ( checkBeforeSubmit() == false )
            {
                return;
            }
            else
            {
                enableFields(); // To Enable all disabled fields

                document.purchaseOrderForm['purchaseOrder.poNumber'].disabled=false;
                document.purchaseOrderForm.action.value="addLineItem";
                document.purchaseOrderForm.submit();
            }
        }
        if( typeof form['purchaseOrder.poHold'] != "undefined" )
        {
            if( form['purchaseOrder.poHold'].checked == false )
            {
                calculateTotal();
                if ( checkBeforeSubmit() == false )
                {
                    return;
                }
                else
                {
                    enableFields(); // To Enable all disabled fields

                    document.purchaseOrderForm['purchaseOrder.poNumber'].disabled=false;
                    document.purchaseOrderForm.action.value="addLineItem";
                    document.purchaseOrderForm.submit();
                }
            }
         }
    }
}

function confirmPO()
{
    if( document.purchaseOrderForm['purchaseOrder.poStatus'] != null )
    {
        if ( document.purchaseOrderForm['purchaseOrder.poNumber'].value.length == 0 || document.purchaseOrderForm['purchaseOrder.poStatus'].value == '4' || document.purchaseOrderForm['purchaseOrder.poStatus'].value == '5' )     //added by phani 30/04/04
        {
            return;
        }
    }
    var selectedPoType = "";
    var selectedPoStatus = "";
	var form = document.purchaseOrderForm;
	var paLineItem = document.getElementById("lineItemErrors");
	var errors ='';
	var flag= false;
	var count = document.purchaseOrderForm.count.value;

	var paPo = document.getElementById("poErrors");
    paPo.innerHTML = "";

    if ( parseFloat( form['purchaseOrder.subTotal'].value ) > 99999999999999.99 )
    {
        paPo.innerHTML = " <li> Sub Total cannot be greater than 99999999999999.99";
        return;
    }

    if ( parseFloat( form['purchaseOrder.tradeDiscount'].value ) > 999999999999.99 )
    {
        paPo.innerHTML = " <li> Trade Discount cannot be greater than 999999999999.99";
        return;
    }

    if ( parseFloat( form['purchaseOrder.freight'].value ) > 999999999999.99 )
    {
        paPo.innerHTML = " <li> Freight cannot be greater than 999999999999.99";
        return;
    }

    if ( parseFloat( form['purchaseOrder.miscellaneous'].value ) > 999999999999.99 )
    {
        paPo.innerHTML = " <li> Miscellaneous cannot be greater than 999999999999.99";
        return;
    }

    if ( parseFloat( form['purchaseOrder.tax'].value ) > 999999999999.99 )
    {
        paPo.innerHTML = " <li> Tax cannot be greater than 999999999999.99";
        return;
    }

	for( var i=0; i < count ; i++ )
	{
	     flag = form['purchaseOrder.purchaseOrderLineItemList[' + i + '].cancel'].checked;
         //following condition helps in giving the error message, when the requestedQuantity is not equal to quantityCancelled,
         //but, cancel checkbox is checked.
         if ( ( flag ) &&
              ( parseInt( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].requestedQuantity'].value ) !=
                parseInt( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].quantityCancelled'].value ) ) )
         {
            paLineItem.innerHTML =  "<li>" + "Requested Quantity and Quantity Cancelled should be same to Cancel Line Item No"+( i + 1 );
            return;
         }
         /*
		 // allowes disable/enable the line item, only when the status is new or cancel
		 if(((form['purchaseOrder.purchaseOrderLineItemList[' + i + '].poLineItemStatus'].value != 1) && (form['purchaseOrder.purchaseOrderLineItemList[' + i + '].poLineItemStatus'].value  != 6)) && (flag == true))
		{
			  errors= "<li>" + "Please enter Cancelled Quantity to  Cancel the Purchase Order Line Item No " + ( i + 1 ) ;

		}*/
		flag= false;

        //Quantity Invoice + Quantity Shippped Sould be less than Quantity Ordered + Quantity Cancelled.
        var requestedQty = parseInt( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].requestedQuantity'].value );
        var cancelledQty = parseInt( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].quantityCancelled'].value );
        var shippedQty   = parseInt( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].quantityInvoiced'].value  );
        var invoicedQty  = parseInt( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].quantityShipped'].value   );
        var greaterOfShippedAndInvoiced = 0;
        if ( shippedQty > invoicedQty )
        {
            greaterOfShippedAndInvoiced = shippedQty;
        }
        else
        {
            greaterOfShippedAndInvoiced = invoicedQty;
        }

        if ( ((requestedQty - cancelledQty) < (greaterOfShippedAndInvoiced)) &&  ( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].poLineItemStatus'].value != 4 && form['purchaseOrder.purchaseOrderLineItemList[' + i + '].poLineItemStatus'].value != 5 ) )
        {
            paLineItem.innerHTML =  "<li>" + "The Requested Quantity can't be less than remaining quantity in Line Item No"+( i + 1 );
            return;
        }
	}
	if ( errors != '')
	{
	    paLineItem.innerHTML = errors;
		return;
	}

    if ( checkBeforeSubmit() == false )
    {
        return;
    }
    else
    {
        enableFields(); // To enable all disabled fields.

        selectedPoType = document.purchaseOrderForm['purchaseOrder.poTypeId'].selectedIndex;
        document.purchaseOrderForm['purchaseOrder.poTypeLabel'].value = document.purchaseOrderForm['purchaseOrder.poTypeId'].options[selectedPoType].innerText;

        if( document.purchaseOrderForm['purchaseOrder.poStatus'] != null )
        {
            selectedPoStatus = document.purchaseOrderForm['purchaseOrder.poStatus'].selectedIndex;
            document.purchaseOrderForm['purchaseOrder.poStatusLabel'].value = document.purchaseOrderForm['purchaseOrder.poStatus'].options[selectedPoStatus].innerText;
        }
        document.purchaseOrderForm.action.value="confirm";
        document.purchaseOrderForm.submit();
    }
}

function vendorOnChange()
{
    //It has to be submitted to server, only when previous Selected vendorId's value is different from vendoId's value selected now.
    if ( document.purchaseOrderForm.previousVendorId.value != document.purchaseOrderForm['purchaseOrder.vendorId'].value )
    {
        document.purchaseOrderForm['purchaseOrder.poNumber'].disabled=false;
        document.purchaseOrderForm.action.value='loadItemsByVendor';
        document.purchaseOrderForm.submit();
    }
    else
    {
        return;
    }
}

function calculate()
{
    if( document.purchaseOrderForm['purchaseOrder.poStatus'] != null )
    {
        if ( document.purchaseOrderForm['purchaseOrder.poNumber'].value.length == 0 || document.purchaseOrderForm['purchaseOrder.poStatus'].value == '4' || document.purchaseOrderForm['purchaseOrder.poStatus'].value == '5' )
        {
            return;
        }
    }
    if ( document.purchaseOrderForm['purchaseOrder.poNumber'].value.length > 0 )    //added by phani 30/04/04
    {
        var form = document.purchaseOrderForm;
        if( form['purchaseOrder.poHold'].checked == false )  //added phani 22/04/04
        {

            calculateTotal();
            if ( checkBeforeSubmit() == false )
            {
                return;
            }
            else
            {
                enableFields() // To enable all disabled fields
                document.purchaseOrderForm['purchaseOrder.poNumber'].disabled=false;
                document.purchaseOrderForm.action.value='calculate';
                document.purchaseOrderForm.submit();
            }
        }
    }
}

function getPartDescription(selectedItem)
{
    var mrkPartNo;
    var size;
    var form = document.purchaseOrderForm;
    var tempSelectedName = selectedItem.name;

    var tempStart = tempSelectedName.lastIndexOf("["); // Get the Starting index no of [
    var tempEnd = tempSelectedName.lastIndexOf("]");   // Get the Ending index no of ]
    var indexNo = parseInt (tempSelectedName.substring( tempStart + 1, tempEnd ) );
    size = keys.length;

    mrkPartNo = form['purchaseOrder.purchaseOrderLineItemList[' + indexNo + '].marketingPartNo'].value;

    // Assign the selected Marketing part number value to Manufacturing part number text box.
	if( mrkPartNo != -1 && mrkPartNo.length > 0 )
	{
		mrkPartNo = mrkPartNo.toLowerCase().trim();

		for(i=0; i < size; i++)
		{
			// Assign the new Purchase Tax schedule Id to the line item mPurchaseItemTaxScheduleId hidden field.
			//form['purchaseOrder.purchaseOrderLineItemList[' + indexNo + '].purchaseItemTaxScheduleId'].value = form['purchaseOrder.purchaseAddressTaxScheduleId'].value;

			if( mrkPartNo == keys[i].toLowerCase().trim() )
			{
				form['purchaseOrder.purchaseOrderLineItemList[' + indexNo + '].lineItemDescription'].value = comments[i];
				form['purchaseOrder.purchaseOrderLineItemList[' + indexNo + '].manufacturingPartNo'].value = mfgPartNoValues[i];
				/*
				form['purchaseOrder.purchaseOrderLineItemList[' + indexNo + '].unitCost'].value = parseDec( round( unitCostValue[i] ), 2, '.' );
				form['purchaseOrder.purchaseOrderLineItemList[' + indexNo + '].purchaseItemTaxScheduleId'].value = scheduleIdValues[i] ;
				form['purchaseOrder.purchaseOrderLineItemList[' + indexNo + '].purchaseTaxOption'].value = taxOptionValues[i];
				form['purchaseOrder.purchaseOrderLineItemList[' + indexNo + '].manufacturingPartNo'].value = mfgPartNoValues[i];
				*/
				break;
			}
			else
			{
				form['purchaseOrder.purchaseOrderLineItemList[' + indexNo + '].lineItemDescription'].value = "";
				//form['purchaseOrder.purchaseOrderLineItemList[' + indexNo + '].unitCost'].value = "0.00";
				//form['purchaseOrder.purchaseOrderLineItemList[' + indexNo + '].manufacturingPartNo'].value = "";
			}
		}
	}
	else
	{
		form['purchaseOrder.purchaseOrderLineItemList[' + indexNo + '].lineItemDescription'].value = "";
		form['purchaseOrder.purchaseOrderLineItemList[' + indexNo + '].manufacturingPartNo'].value = "";
	}
    //Erasing Site ID, when even Part changed.
    //form['purchaseOrder.purchaseOrderLineItemList[' + indexNo + '].siteId'].value = "";
}

function changeExtendedCost()
{
    var form = document.purchaseOrderForm;
    var count = document.purchaseOrderForm.count.value;

    var unitCost;
    var requestedQuantity;
    var extendedCost;

    for( i=0; i< count; i++ )
    {
        unitCost =  form['purchaseOrder.purchaseOrderLineItemList[' + i + '].unitCost'].value;
        requestedQuantity = form['purchaseOrder.purchaseOrderLineItemList[' + i + '].requestedQuantity'].value;

        //phani 21/04/2004
        if ( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].extendedCost'].value == '' ||
             form['purchaseOrder.purchaseOrderLineItemList[' + i + '].extendedCost'].value == '0' ||
             parseFloat ( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].extendedCost'].value ) < 0 )
        {
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].extendedCost'].value = '0.00';
        }
        else
        {
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].extendedCost'].value =
                parseMoney( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].extendedCost'].value );
        }
        //upto here

        //added phani 14/04/2004
        if ( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].extendedCost'].value > 99999999999999.99 )
        {
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].extendedCost'].value = 99999999999999.99;
        }
        //upto here

        extendedCost = form['purchaseOrder.purchaseOrderLineItemList[' + i + '].extendedCost'].value;

        if ( parseFloat ( extendedCost ) == 0 )
        {
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].unitCost'].value = '0.00';
        }

        //if( (  extendedCost == '0' ) || ( extendedCost == '' ) || ( requestedQuantity == '0' ) || ( requestedQuantity == '' ) || ( requestedQuantity == '0.00' ) )
        if( ( requestedQuantity == '0' ) || ( requestedQuantity == '' ) || ( requestedQuantity == '0.00' ) )
        {
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].extendedCost'].value =
                parseDec( round( ( parseFloat( parseFloat( requestedQuantity ) * parseFloat( unitCost ) ) ) ), 2, '.' ) ;
        }
        else if ( ( parseFloat ( extendedCost ) != 0 ) && ( requestedQuantity != '0' )  &&  ( unitCost != '0' )  )
        {
            if( ( parseFloat( extendedCost) / parseFloat( requestedQuantity ) ) != parseFloat( unitCost ) )
            {
                form['purchaseOrder.purchaseOrderLineItemList[' + i + '].unitCost'].value = parseDec( round(  parseFloat( ( parseFloat( extendedCost ) / parseFloat( requestedQuantity ) ) ) ), 2, '.'  );
            }
        }
    }
    //added by phani 23/04/2004 for calculating subtotal whenever we change the extended cost.
    calculateTotal ();
}

function calculateTotal()
{
	var paPo = document.getElementById("poErrors"); //added by phani 23 March 2004
    paPo.innerHTML = "";

    // Totals Calculation starts here.
    var form = document.purchaseOrderForm;
    var count = document.purchaseOrderForm.count.value;
    var requestedQuantity = 0;
    var unitCost = 0.00;
    var extendedCost = 0.00;
    var subTotal = 0.00;
    var total = 0.00;
    var poSubTotal = 0.00;
    var quantityCancelled = 0;
    var totalRequested = 0;
    var totalCancelled = 0;
    var totalCostOfItems = 0.00; // added by Phani on 23 March 2004 for calculating total cost of Items.

    var paLineItem = document.getElementById("lineItemErrors"); //added phani 09/09/2004
    paLineItem.innerHTML = '';
    var pa = document.getElementById("lineItemErrors");
        pa.innerHTML = '';

    for( i=0; i < count; ++i )
    {
        // Setting the feilds to 0 if the user does not enter anything.
        if ( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].requestedQuantity'].value == '' ||
             parseInt (form['purchaseOrder.purchaseOrderLineItemList[' + i + '].requestedQuantity'].value) < 0 )
        {
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].requestedQuantity'].value = '0';
        }
        else
        {
             form['purchaseOrder.purchaseOrderLineItemList[' + i + '].requestedQuantity'].value =
                parseDec ( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].requestedQuantity'].value, 0 );
        }

        if (  form['purchaseOrder.purchaseOrderLineItemList[' + i + '].quantityCancelled'].value == '' ||
              form['purchaseOrder.purchaseOrderLineItemList[' + i + '].quantityCancelled'].value < 0 )
        {
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].quantityCancelled'].value = '0';
        }
        else
        {
             form['purchaseOrder.purchaseOrderLineItemList[' + i + '].quantityCancelled'].value =
                parseDec ( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].quantityCancelled'].value, 0 );
        }

        if ( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].unitCost'].value == '' ||
             form['purchaseOrder.purchaseOrderLineItemList[' + i + '].unitCost'].value == '0' ||
             form['purchaseOrder.purchaseOrderLineItemList[' + i + '].unitCost'].value < 0 )
        {
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].unitCost'].value = '0.00';
        }
        else
        {
             form['purchaseOrder.purchaseOrderLineItemList[' + i + '].unitCost'].value =
                parseMoney ( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].unitCost'].value );
        }
    }

    // added to check Quantity Cacelled with Quantity Requested. phani 09/04/2004
    for(var j=0; j < count; ++j)
    {
       if ( ( parseInt ( form['purchaseOrder.purchaseOrderLineItemList[' + j + '].quantityCancelled'].value )) >
            ( parseInt ( form['purchaseOrder.purchaseOrderLineItemList[' + j + '].requestedQuantity'].value )) )
       {
            errors = "<li> Quantity Cancelled should be less than Requested Quantity in Line Item No " + parseInt(j + 1);
            pa.innerHTML = errors;
            //form['purchaseOrder.purchaseOrderLineItemList[' + j + '].quantityCancelled'].focus();
            //form['purchaseOrder.purchaseOrderLineItemList[' + j + '].quantityCancelled'].select();
            return false;
       }
       pa.innerHTML = '';
    }

    for( i=0; i < count; ++i )
    {
        unitCost =  form['purchaseOrder.purchaseOrderLineItemList[' + i + '].unitCost'].value;
        if ( unitCost > 99999999999999.99 )
        {
            unitCost = 99999999999999.99;
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].unitCost'].value = unitCost;
            pa.innerHTML = "<li> Unit Cost can not be more than 99999999999999.99"; //added phani 22/04/04
        }

        requestedQuantity = form['purchaseOrder.purchaseOrderLineItemList[' + i + '].requestedQuantity'].value;
        extendedCost = ( parseFloat( requestedQuantity ) * parseFloat(  unitCost ) );
        quantityCancelled = form['purchaseOrder.purchaseOrderLineItemList[' + i + '].quantityCancelled'].value;

        if ( extendedCost > 99999999999999.99 )
        {
            extendedCost = 99999999999999.99;
        }

        form['purchaseOrder.purchaseOrderLineItemList[' + i + '].extendedCost'].value = parseDec( round( parseFloat( extendedCost ) ), 2, '.' );
        subTotal = parseDec( round( ( parseFloat( subTotal ) + parseFloat( extendedCost ) ) ), 2, '.' );

        // PO Sub Total calculation.
        totalRequested = totalRequested + ( parseInt ( requestedQuantity ) * ( unitCost ) );
        totalCancelled = totalCancelled + ( parseInt ( quantityCancelled ) * ( unitCost ) );
    }

    if ( subTotal > 99999999999999.99 )
    {
        subTotal = 99999999999999.99;
    }

    form['purchaseOrder.subTotal'].value = parseDec( round( parseFloat( subTotal ) ), 2, '.' );
    //form['purchaseOrder.remainingPoSubTotal'].value = parseDec( round( ( parseFloat( totalRequested ) - parseFloat( totalCancelled ) ) ), 2, '.' );

	if ( form['purchaseOrder.freight'].value == '' ||
         form['purchaseOrder.freight'].value == '0' ||
         form['purchaseOrder.freight'].value < 0 )
	{
		form['purchaseOrder.freight'].value = '0.00';
	}
    else
    {
        form['purchaseOrder.freight'].value = parseMoney ( form['purchaseOrder.freight'].value );
    }

	if ( form['purchaseOrder.miscellaneous'].value == '' ||
         form['purchaseOrder.miscellaneous'].value == '0' ||
         form['purchaseOrder.miscellaneous'].value < 0 )
	{
		form['purchaseOrder.miscellaneous'].value = '0.00';
	}
    else
    {
        form['purchaseOrder.miscellaneous'].value = parseMoney ( form['purchaseOrder.miscellaneous'].value );
    }

	if ( form['purchaseOrder.tax'].value == '' ||
         form['purchaseOrder.tax'].value == '0' ||
         form['purchaseOrder.tax'].value < 0 )
	{
		form['purchaseOrder.tax'].value = '0.00';
	}
    else
    {
        form['purchaseOrder.tax'].value = parseMoney ( form['purchaseOrder.tax'].value );
    }

	if ( form['purchaseOrder.tradeDiscount'].value == '' ||
         form['purchaseOrder.tradeDiscount'].value == '0' ||
         form['purchaseOrder.tradeDiscount'].value < 0 )
	{
		form['purchaseOrder.tradeDiscount'].value = '0.00';
	}
    else
    {
        form['purchaseOrder.tradeDiscount'].value = parseMoney ( form['purchaseOrder.tradeDiscount'].value );
    }

	totalCostOfItems = parseFloat( totalRequested ) - parseFloat( totalCancelled );

	if( parseFloat( form['purchaseOrder.tradeDiscount'].value ) > parseFloat( totalCostOfItems ) )
    {
        paPo.innerHTML = " <li> Enter a Smaller Trade Discount. The Trade Discount must be less than the Sub Total minus the Total for Canceled Items";
        return false;
    }

    total = ( parseFloat( form['purchaseOrder.freight'].value ) + parseFloat( form['purchaseOrder.miscellaneous'].value ) + parseFloat( form['purchaseOrder.tax'].value ) - parseFloat( form['purchaseOrder.tradeDiscount'].value ) );

    form['purchaseOrder.total'].value = parseDec( round( parseFloat( ( parseFloat( total ) + ( parseFloat( subTotal ) ) ) ) ), 2, '.' );

    if ( form['purchaseOrder.total'].value <= 99999999999999.99 )
    {
        form['purchaseOrder.total'].value = parseDec( round( form['purchaseOrder.total'].value ), 2, '.' );
    }
    else
    {
        form['purchaseOrder.total'].value = 99999999999999.99;
    }
}

function validateHold()
{
    var form = document.purchaseOrderForm;
    var count = document.purchaseOrderForm.count.value;

    var paPo = document.getElementById("poErrors");
    var paLineItem = document.getElementById("lineItemErrors");
    paPo.innerHTML = "";
    paLineItem.innerHTML = "";
	var errors ='';
	var flag= false;

    if ( checkBeforeSubmit() == false )
    {
        form['purchaseOrder.poHold'].checked = false;
        return;
    }
    else
    {
        if ( parseFloat( form['purchaseOrder.subTotal'].value ) > 99999999999999.99 )
        {
            paPo.innerHTML = " <li> Sub Total cannot be greater than 99999999999999.99";
            form['purchaseOrder.poHold'].checked = false;
            return;
        }

        if ( parseFloat( form['purchaseOrder.tradeDiscount'].value ) > 999999999999.99 )
        {
            paPo.innerHTML = " <li> Trade Discount cannot be greater than 999999999999.99";
            form['purchaseOrder.poHold'].checked = false;
            return;
        }

        if ( parseFloat( form['purchaseOrder.freight'].value ) > 999999999999.99 )
        {
            paPo.innerHTML = " <li> Freight cannot be greater than 999999999999.99";
            form['purchaseOrder.poHold'].checked = false;
            return;
        }

        if ( parseFloat( form['purchaseOrder.miscellaneous'].value ) > 999999999999.99 )
        {
            paPo.innerHTML = " <li> Miscellaneous cannot be greater than 999999999999.99";
            form['purchaseOrder.poHold'].checked = false;
            return;
        }

        if ( parseFloat( form['purchaseOrder.tax'].value ) > 999999999999.99 )
        {
            paPo.innerHTML = " <li> Tax cannot be greater than 999999999999.99";
            form['purchaseOrder.poHold'].checked = false;
            return;
        }

        for( var i=0; i < count ; i++ )
        {
            flag = form['purchaseOrder.purchaseOrderLineItemList[' + i + '].cancel'].checked;
            //following condition helps in giving the error message, when the requestedQuantity is not equal to quantityCancelled,
            //but, cancel checkbox is checked.  Added by phani 06/04/2004
            if ( ( flag ) &&
                ( parseInt( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].requestedQuantity'].value ) !=
                    parseInt( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].quantityCancelled'].value ) ) )
            {
                errors = "<li>" + "Requested Quantity and Quantity Cancelled should be same to Cancel Line Item No"+( i + 1 );
                flag= false;
            }
            /*
            // allowes disable/enable the line item, only when the status is new or cancel
            if(((form['purchaseOrder.purchaseOrderLineItemList[' + i + '].poLineItemStatus'].value != 1) && (form['purchaseOrder.purchaseOrderLineItemList[' + i + '].poLineItemStatus'].value  != 6)) && (flag == true))
            {
                  errors= "<li>" + "Please enter Cancelled Quantity to  Cancel the Purchase Order Line Item No " + ( i + 1 ) ;

            } */
            flag= false;
        }
        if ( errors != '')
        {

            paLineItem.innerHTML = errors;
            form['purchaseOrder.poHold'].checked = false;
            return;
        }
    }
}

function hold()
{
    var form = document.purchaseOrderForm;
    var count = document.purchaseOrderForm.count.value;
    var paPo = document.getElementById("poErrors");
    paPo.innerHTML = "";

    var requestedQty = "";
    var cancelledQty = "";
    var shippedQty   = "";
    var invoicedQty  = "";
	var poLineItemStatus = "";


    if( document.purchaseOrderForm['purchaseOrder.poStatus'] != null )
    {
        if ( document.purchaseOrderForm['purchaseOrder.poNumber'].value.length == 0 || document.purchaseOrderForm['purchaseOrder.poStatus'].value == '4' || document.purchaseOrderForm['purchaseOrder.poStatus'].value == '5' )
        {
            paPo.innetHTML = "<li> Purchase Order with Received or Closed status cannot be Modified.";
            return;
        }
    }

    if( form['purchaseOrder.poHold'].checked == true )
    {
        // Po related Fields.
        form['purchaseOrder.vendorId'].disabled = true;
        form['purchaseOrder.poDate'].disabled = true;
        form['purchaseOrder.requistionDate'].disabled = true;
        form['purchaseOrder.requiredDate'].disabled = true;
        form['purchaseOrder.promisedDate'].disabled = true;
        form['purchaseOrder.promisedShipDate'].disabled = true;
        form['purchaseOrder.poTypeId'].disabled = true;
        form['purchaseOrder.tradeDiscount'].disabled = true;
        form['purchaseOrder.freight'].disabled = true;
        form['purchaseOrder.commentDescription'].disabled = true;
        form['purchaseOrder.miscellaneous'].disabled = true;
        form['purchaseOrder.tax'].disabled = true;

        if( form['purchaseOrder.poTypeId'].value == 2 )
        {
            form['purchaseOrder.customerId'].disabled = true;
            form['purchaseOrder.shippToAddressId'].disabled = true;
        }

        // added by rajkumar
        if( form['purchaseOrder.poStatus'] != null )
        {
            form['purchaseOrder.poStatus'].disabled = true;
        }

        // Po Lineitem related Fields
        for( i = 0; i < count; i++ )
        {
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].marketingPartNo'].disabled = true;
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].manufacturingPartNo'].disabled = true;
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].lineItemDescription'].disabled = true;
            //form['purchaseOrder.purchaseOrderLineItemList[' + i + '].siteId'].disabled = true;
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].requestedQuantity'].disabled = true;
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].quantityCancelled'].disabled = true;
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].unitCost'].disabled = true;
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].extendedCost'].disabled = true;
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].poLineItemStatus'].disabled = true;
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].cancel'].disabled = true; //added phani 22/04/04
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].requiredDate'].disabled = true;
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].promisedDate'].disabled = true;
        }
    }
    else
    {
        // Po related Fields.
        // If Purchase Order is new then allow user to change Vendor Id.In add new mode Po Status is not available.
        // If the User is in edit mode then do not allow to change vendor Id.
        if( form['purchaseOrder.poStatus'] == null )
        {
            form['purchaseOrder.vendorId'].disabled = false;
        }
        form['purchaseOrder.poDate'].disabled = false;
        form['purchaseOrder.requistionDate'].disabled = false;
        form['purchaseOrder.requiredDate'].disabled = false;
        form['purchaseOrder.promisedDate'].disabled = false;
        form['purchaseOrder.promisedShipDate'].disabled = false;
        form['purchaseOrder.poTypeId'].disabled = false;
        form['purchaseOrder.tradeDiscount'].disabled = false;
        form['purchaseOrder.freight'].disabled = false;
        form['purchaseOrder.commentDescription'].disabled = false;
        form['purchaseOrder.miscellaneous'].disabled = false;
        form['purchaseOrder.tax'].disabled = false;

        if( form['purchaseOrder.poTypeId'].value == 2 )
        {
            form['purchaseOrder.customerId'].disabled = false;
            form['purchaseOrder.shippToAddressId'].disabled = false;
        }

        if( form['purchaseOrder.poStatus'] != null )
        {
            form['purchaseOrder.poStatus'].disabled = true;  //modified to true phani 25/04/2004
        }

        // Po Lineitem related Fields
        for( i = 0; i < count; i++ )
        {
            requestedQty = parseInt( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].requestedQuantity'].value );
            cancelledQty = parseInt( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].quantityCancelled'].value );
            shippedQty   = parseInt( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].quantityInvoiced'].value  );
            invoicedQty  = parseInt( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].quantityShipped'].value   );
            poLineItemStatus = form['purchaseOrder.purchaseOrderLineItemList[' + i + '].poLineItemStatus'].value;

            if ( ( requestedQty != cancelledQty ) || requestedQty == 0
                 || form['purchaseOrder.purchaseOrderLineItemList[' + i + '].cancel'].checked == false )
            {

                if( ( poLineItemStatus == 1 ) || ( poLineItemStatus == 2 ) || ( poLineItemStatus == 3 ) || ( poLineItemStatus == 6 ) )
                {
                    //form['purchaseOrder.purchaseOrderLineItemList[' + i + '].manufacturingPartNo'].disabled = false;

                    if ( poLineItemStatus == 1 || poLineItemStatus == 6 )
                    {
					    form['purchaseOrder.purchaseOrderLineItemList[' + i + '].marketingPartNo'].disabled = false;
                    }
                    form['purchaseOrder.purchaseOrderLineItemList[' + i + '].lineItemDescription'].disabled = false;
                    //form['purchaseOrder.purchaseOrderLineItemList[' + i + '].siteId'].disabled = false;
                    form['purchaseOrder.purchaseOrderLineItemList[' + i + '].requestedQuantity'].disabled = false;
                    form['purchaseOrder.purchaseOrderLineItemList[' + i + '].quantityCancelled'].disabled = false;
                    form['purchaseOrder.purchaseOrderLineItemList[' + i + '].unitCost'].disabled = false;
                    form['purchaseOrder.purchaseOrderLineItemList[' + i + '].extendedCost'].disabled = false;
                    //form['purchaseOrder.purchaseOrderLineItemList[' + i + '].poLineItemStatus'].disabled = false; //phani 26/03/2004
                    // Added by SharatH on 20th May 04
                    form['purchaseOrder.purchaseOrderLineItemList[' + i + '].requiredDate'].disabled = false;
                    form['purchaseOrder.purchaseOrderLineItemList[' + i + '].promisedDate'].disabled = false;
                }
            }

            //Disables cancel checkbox, If the Status is RECEIVED OR CLOSED OR
            //When the Status is RELEASED or Change Order, Check weather some Qty Shipped or Invoiced.
            if (  ( poLineItemStatus == 4 ) || ( poLineItemStatus == 5 ) || ( ( poLineItemStatus == 2  || poLineItemStatus == 3 ) && ( shippedQty > 0 || invoicedQty > 0 ) )  )
            {
                    form['purchaseOrder.purchaseOrderLineItemList[' + i + '].cancel'].disabled = true;
            }
            else
            {
                form['purchaseOrder.purchaseOrderLineItemList[' + i + '].cancel'].disabled = false;
            }
        }
    }
    onLoad();
}

function purchaseTaxScheduleEntry()
{
    newWindow = window.open ('<%=chipTracContext%>/purchaseOrder.do?action=purchaseTaxScheduleEntry','optionsPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=yes,scrollbars=no,width=500,height=270,resizable=yes');
    newWindow.focus();
}
<%
    /*
    Commented on march 15th 04 as getting the part nos from GP
    if( request.getAttribute("marketingDescriptions") != null )
    {
         StringBuffer strBuffer = null;
         java.util.HashMap mapComments = null;
         try{
                 mapComments = (java.util.HashMap) request.getAttribute("marketingDescriptions");
                 java.util.Iterator mapKeyIterator = mapComments.keySet().iterator();
                 int count = 0;
                 strBuffer = new StringBuffer();
                 while( mapKeyIterator.hasNext() )
                 {
                     Object key = mapKeyIterator.next();
                     strBuffer.append("keys[").append(count).append("]='").append(key).append("';\n");
                     //strBuffer.append("comments[").append(count).append("]='").append(StringUtils.escapeHTML((String)mapComments.get(key))).append("';\n");
                     out.print( "comments["+count+"]='");
                     if(mapComments.get(key)!=null){
                        out.print(StringUtils.escapeSpecialString((String)mapComments.get(key)) );
                     }
                     out.println("';");
                     count++;
                 }
            out.println(strBuffer.toString());
            }
            catch(Exception ex)
            {
                System.out.println(ex);
            }
     }

    */
        if( request.getAttribute("marketingDescriptions") != null )
        {
             StringBuffer strBuffer = null;
             java.util.HashMap mapComments = null;
             try{
                     mapComments = (java.util.HashMap) request.getAttribute("marketingDescriptions");
                     java.util.Iterator mapKeyIterator = mapComments.keySet().iterator();
                     int count = 0;
                     strBuffer = new StringBuffer();
                     while( mapKeyIterator.hasNext() )
                     {
                         Object key = mapKeyIterator.next();
                         strBuffer.append("keys[").append(count).append("]='").append(key).append("';\n");
                         //strBuffer.append("comments[").append(count).append("]='").append(StringUtils.escapeHTML((String)mapComments.get(key))).append("';\n");
                         out.print( "comments["+count+"]='");
                         if(mapComments.get(key)!=null){
                            //System.out.println(StringUtils.escapeSpecialString((String)mapComments.get(key)));
                            out.print(StringUtils.escapeSpecialString((String)mapComments.get(key)) );
                         }
                         out.println("';");
                         count++;
                     }
                out.println(strBuffer.toString());
                }
                catch(Exception ex)
                {
                    System.out.println(ex);
                }
         }

        if( request.getAttribute("manufacturingPartNos") != null )
        {
             StringBuffer strBuffer = null;
             java.util.HashMap mapMfgPartNos = null;
             try{
                     mapMfgPartNos = (java.util.HashMap) request.getAttribute("manufacturingPartNos");
                     java.util.Iterator mapKeyIterator = mapMfgPartNos.keySet().iterator();
                     int count = 0;
                     strBuffer = new StringBuffer();
                     while( mapKeyIterator.hasNext() )
                     {
                         Object key = mapKeyIterator.next();
                         strBuffer.append("mfgPartNoKeys[").append(count).append("]='").append(key).append("';\n");
                         out.print( "mfgPartNoValues["+count+"]='");
                         if(mapMfgPartNos.get(key)!=null){
                            out.print(StringUtils.escapeSpecialString((String)mapMfgPartNos.get(key)) );
                         }
                         out.println("';");
                         count++;
                     }
                out.println(strBuffer.toString());
                }
                catch(Exception ex)
                {
                    System.out.println(ex);
                }
         }

        if( request.getAttribute("marketingPartNoUnitCostList") != null )
        {
             StringBuffer strBuffer = null;
             ArrayList unitCostList = new ArrayList();

             try
             {
                    unitCostList = ( ArrayList ) request.getAttribute("marketingPartNoUnitCostList");
                    LabelValueBean unitLb;

                     int count = 0;
                    String itemNo = "";
                    float unitCost = 0.0f;
                    strBuffer = new StringBuffer();
                    for(int j = 0; j < unitCostList.size(); j++ )
                    {
                        unitLb = ( LabelValueBean ) unitCostList.get(j);
                        itemNo = unitLb.getLabel();
                        unitCost = Float.parseFloat( unitLb.getValue() );

                        strBuffer.append("unitCostValue[").append(count).append("]='").append( unitCost ).append("';\n");

                        out.print( "item["+count+"]='");
                        out.print( StringUtils.escapeSpecialString( itemNo ) );

                         out.println("';");
                         count++;
                    }
                out.println( strBuffer.toString() );
                }
                catch(Exception ex)
                {
                    System.out.println(ex);
                }
         }

    // Added for Tax calculations
        if( request.getAttribute("purchaseTaxSchedulesList") != null )
        {
             StringBuffer strBuffer = null;
             java.util.HashMap mapTaxSchedule = null;
             try{
                     mapTaxSchedule = (java.util.HashMap) request.getAttribute("purchaseTaxSchedulesList");
                     java.util.Iterator mapKeyIterator = mapTaxSchedule.keySet().iterator();
                     int count = 0;
                     strBuffer = new StringBuffer();
                     while( mapKeyIterator.hasNext() )
                     {
                         Object key = mapKeyIterator.next();
                         strBuffer.append("scheduleIdKeys[").append(count).append("]='").append(key).append("';\n");

                         out.print( "scheduleIdValues["+count+"]='");
                         if(mapTaxSchedule.get(key)!=null){

                            out.print(StringUtils.escapeSpecialString((String)mapTaxSchedule.get(key)) );
                         }
                         out.println("';");
                         count++;
                     }
                out.println(strBuffer.toString());
                }
                catch(Exception ex)
                {
                    System.out.println(ex);
                }
         }

        if( request.getAttribute("purchaseTaxOptionsList") != null )
        {
             StringBuffer strBuffer = null;
             java.util.HashMap mapTaxOptions = null;
             try{
                     mapTaxOptions = (java.util.HashMap) request.getAttribute("purchaseTaxOptionsList");
                     java.util.Iterator mapKeyIterator = mapTaxOptions.keySet().iterator();
                     int count = 0;
                     strBuffer = new StringBuffer();
                     while( mapKeyIterator.hasNext() )
                     {
                         Object key = mapKeyIterator.next();
                         strBuffer.append("taxOptionKeys[").append(count).append("]='").append(key).append("';\n");

                         out.print( "taxOptionValues["+count+"]='");
                         if(mapTaxOptions.get(key)!=null){

                            out.print(StringUtils.escapeSpecialString((String)mapTaxOptions.get(key)) );
                         }
                         out.println("';");
                         count++;
                     }
                out.println(strBuffer.toString());
                }
                catch(Exception ex)
                {
                    System.out.println(ex);
                }
         }

        // Added for Drop Ship Type
        if( request.getAttribute( "customerAddressList" ) != null )
        {
            CustomerAddress customerAddress = new CustomerAddress();
            CustomerAddressList  customerAddressList = new CustomerAddressList();

            customerAddressList = ( CustomerAddressList ) request.getAttribute( "customerAddressList" );
            // Get Customer Ids Array
            StringBuffer customerIdsArray       = new StringBuffer();
            // Get Customer Addresses Array
            StringBuffer customerAddressesArray =  new StringBuffer();
            StringBuffer customerContactPersonArray =  new StringBuffer();
            StringBuffer customerAddress1Array =  new StringBuffer();
            StringBuffer customerAddress2Array =  new StringBuffer();
            StringBuffer customerAddress3Array =  new StringBuffer();
            StringBuffer customerCityArray =  new StringBuffer();
            StringBuffer customerStateArray =  new StringBuffer();
            StringBuffer customerZipCodeArray =  new StringBuffer();
            StringBuffer customerCountryArray =  new StringBuffer();
            int arrayIndex = 0;
            String customerIdStr           = "";
            String customerAddressesStr    = "";
            String customerContactPersonStr    = "";
            String customerAddress1Str    = "";
            String customerAddress2Str    = "";
            String customerAddress3Str    = "";
            String customerCityStr    = "";
            String customerStateStr    = "";
            String customerZipCodeStr    = "";
            String customerCountryStr    = "";


            for( int j = 0; j < customerAddressList.size(); j++ )
            {
                customerAddress             = ( CustomerAddress )customerAddressList.get( j );
                customerIdStr               = customerAddress.getCustomerId();
                customerAddressesStr        = customerAddress.getAddressId();
                customerContactPersonStr    = ( customerAddress.getContactPerson() != null ? customerAddress.getContactPerson().trim() : "" );
                customerAddress1Str         = ( customerAddress.getAddress1() != null ? customerAddress.getAddress1().trim() : "" );
                customerAddress2Str         = ( customerAddress.getAddress2() != null ? customerAddress.getAddress2().trim() : "" ) ;
                customerAddress3Str         = ( customerAddress.getAddress3() != null ? customerAddress.getAddress3().trim() : "" );
                customerCityStr             = ( customerAddress.getCity() != null ? customerAddress.getCity().trim() : "" );
                customerStateStr            = ( customerAddress.getState() != null ? customerAddress.getState().trim() : "");
                customerZipCodeStr          = ( customerAddress.getZipcode() != null  ? customerAddress.getZipcode().trim()  : "" );
                customerCountryStr          = ( customerAddress.getCountry() != null ? customerAddress.getCountry().trim() : "");

                customerIdsArray.append( "customerIdsArray[" +  arrayIndex  + "]=\"" + customerIdStr + "\";\n" );
                customerAddressesArray.append( "customerAddressesArray[" +  arrayIndex  + "]=\"" + customerAddressesStr + "\";\n" );
                customerContactPersonArray.append( "customerContactPersonArray[" +  arrayIndex  + "]=\"" + customerContactPersonStr + "\";\n" );
                customerAddress1Array.append( "customerAddress1Array[" +  arrayIndex  + "]=\"" + customerAddress1Str + "\";\n" );
                customerAddress2Array.append( "customerAddress2Array[" +  arrayIndex  + "]=\"" + customerAddress2Str + "\";\n" );
                customerAddress3Array.append( "customerAddress3Array[" +  arrayIndex  + "]=\"" + customerAddress3Str + "\";\n" );
                customerCityArray.append( "customerCityArray[" +  arrayIndex  + "]=\"" + customerCityStr + "\";\n" );
                customerStateArray.append( "customerStateArray[" +  arrayIndex  + "]=\"" + customerStateStr + "\";\n" );
                customerZipCodeArray.append( "customerZipCodeArray[" +  arrayIndex  + "]=\"" + customerZipCodeStr + "\";\n" );
                customerCountryArray.append( "customerCountryArray[" +  arrayIndex  + "]=\"" + customerCountryStr + "\";\n" );

                arrayIndex++;
            }

            out.println( customerIdsArray );
            out.println( customerAddressesArray );
            out.println( customerContactPersonArray );
            out.println( customerAddress1Array );
            out.println( customerAddress2Array );
            out.println( customerAddress3Array );
            out.println( customerCityArray );
            out.println( customerStateArray );
            out.println( customerZipCodeArray );
            out.println( customerCountryArray );

        }
%>
function checkBeforeSubmit()
{
    // This function checks for Marketing Part No before submitting the page.
    var form = document.purchaseOrderForm;
    var count = form.count.value;
	var comment = form['purchaseOrder.commentDescription'].value;
    var paPo = document.getElementById("poErrors");
    var paLineItem = document.getElementById("lineItemErrors");
    var purchaseOrderDate = form['purchaseOrder.poDate'].value;
    var requistionDate      =   form['purchaseOrder.requistionDate'].value;
    var requiredDate        =   form['purchaseOrder.requiredDate'].value;
    var promisedDate        =   form['purchaseOrder.promisedDate'].value;
    var promisedShipDate    =   form['purchaseOrder.promisedShipDate'].value;

    var cancelledExtCost = 0;

    paPo.innerHTML = "";
    paLineItem.innerHTML = "";

	if( form['purchaseOrder.poTypeId'].value == '' )
    {
        paPo.innerHTML = " <li> Please Select Type ";
        return false;
    }
    else if( form['purchaseOrder.vendorId'].value == '' || form['purchaseOrder.vendorId'].value == '-1' )
    {
            paPo.innerHTML = " <li> Please Select Vendor Name ";
            return false;
    }
    else if( !chkDate( purchaseOrderDate, "Purchase Order Date", 'Y' ) )
    {
		paPo.innerHTML = errMsg;
        return false;
    }
    else if( form['purchaseOrder.poTypeId'].value == '2' && ( form['purchaseOrder.customerId'].value == '' || form['purchaseOrder.customerId'].value == '-1') )
    {
        paPo.innerHTML = " <li> Please Select Customer Name";
        return false;
    }
    else if( form['purchaseOrder.poTypeId'].value == '2' && form['purchaseOrder.shippToAddressId'].value == '0' )
    {
        paPo.innerHTML = " <li> Please Select Ship To Address";
        return false;
    }
    else if( !chkDate( requistionDate.trim (), "Requistion Date" , "N" ) )
    {
        paPo.innerHTML = errMsg;
        document.purchaseOrderForm['purchaseOrder.requistionDate'].focus();
        document.purchaseOrderForm['purchaseOrder.requistionDate'].select();
        return false;
    }
    else if ( !chkDate( requiredDate.trim (), "Required Date" , "N" ) )
    {
        paPo.innerHTML = errMsg;
        document.purchaseOrderForm['purchaseOrder.requiredDate'].focus();
        document.purchaseOrderForm['purchaseOrder.requiredDate'].select();
        return false;
    }
    else if( !chkDate( promisedDate.trim (), "Promised Date" , "N" ) )
    {
        paPo.innerHTML = errMsg;
        document.purchaseOrderForm['purchaseOrder.promisedDate'].focus();
        document.purchaseOrderForm['purchaseOrder.promisedDate'].select();
        return false;
    }
    else if( !chkDate( promisedShipDate.trim (), "Promised Ship Date" , "N" ) )
    {
        errors = errors + '<br>' + errMsg;
        document.purchaseOrderForm['purchaseOrder.promisedShipDate'].focus();
        document.purchaseOrderForm['purchaseOrder.promisedShipDate'].select();
        return false;
    }

    for( i = 0; i < count; i++ )
    {
        if( ( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].manufacturingPartNo'].value == '' ) || ( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].manufacturingPartNo'].value == '-1' ) || ( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].manufacturingPartNo'].value == '---- KIT -----' ) )
        {
            paLineItem.innerHTML = " <li> Please Select Part Number in Line Item No " + parseInt(i + 1);
            return false;
        }
        else if( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].lineItemDescription'].value.length > '50' )
        {
            paLineItem.innerHTML = " <li> Description cannot be more than 50 in Line Item No " + parseInt(i + 1);
            return false;
        }/*
        else if ( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].siteId'].value.trim().length == 0 )
        {
           paLineItem.innerHTML = " <li> Please Select Site in Line Item No " + parseInt(i + 1);
           return false;
        }*/
        else if( parseInt( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].quantityCancelled'].value ) > parseInt( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].requestedQuantity'].value ) )
        {
            paLineItem.innerHTML = " <li> Quantity Cancelled should be less than Requested Quantity in Line Item No " + parseInt(i + 1);
            return false;
        }
        else if( !chkDate( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].requiredDate'].value, "Required Date", 'N' ) )
        {
            paLineItem.innerHTML = errMsg;
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].requiredDate'].select();
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].requiredDate'].focus();
            return false;
        }
        else if( !chkDate( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].promisedDate'].value, "Promised Date", 'N' ) )
        {
            paLineItem.innerHTML = errMsg;
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].promisedDate'].select();
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].promisedDate'].focus();
            return false;
        }

        //If Cancel = true and Qty Canceled = qty requested then add the Ext cost.
        if( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].cancel'].checked == true && ( parseInt( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].requestedQuantity'].value ) == parseInt( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].quantityCancelled'].value ) ) )
        {
            cancelledExtCost = parseFloat( cancelledExtCost ) + parseFloat( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].extendedCost'].value );
        }
    }

    if ( parseFloat( cancelledExtCost ) > 99999999999999.98 )
    {
        cancelledExtCost = 99999999999999.98;
    }

	//To check the negetive values in Requested Quantity,QtyCancelled,UnitCost.
	for( i = 0; i < count; i++ )
	{
		if((parseInt( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].requestedQuantity'].value )) < 0)
		{
			paLineItem.innerHTML = " <li> Requested Quantity should be more than zero in LineItemNo" + parseInt(i + 1);
			(form['purchaseOrder.purchaseOrderLineItemList[' + i + '].requestedQuantity'].select());
            return false;
		}
		if( parseInt( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].quantityCancelled'].value ) < 0)
		{
			paLineItem.innerHTML = " <li> Quantity Cancelled should be more than zero in LineItemNo" + parseInt(i + 1);
			parseInt( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].quantityCancelled'].select());
			return false;
		}
		if(parseInt(form['purchaseOrder.purchaseOrderLineItemList[' + i + '].unitCost'].value) < 0)
		{
			paLineItem.innerHTML = " <li> Unit Cost should be more than zero in LineItemNo" + parseInt(i + 1);
			form['purchaseOrder.purchaseOrderLineItemList[' + i + '].unitCost'].select();
			return false;
		}
	}

    if( parseFloat( form['purchaseOrder.tradeDiscount'].value) > ( parseFloat( form['purchaseOrder.subTotal'].value - parseFloat( cancelledExtCost ) ) ) )
    {
        paPo.innerHTML = " <li> Enter a Smaller Trade Discount. The Trade Discount must be less than the Sub Total minus the Total for Canceled Items";
        return false;
    }

	if ( comment.length > 450 )
	{
		paLineItem.innerHTML = " <li> Comment length cannot be more than 450";
		return false;
	}
}

function printableVersion()
{
    if( document.purchaseOrderForm['purchaseOrder.poStatus'] != null )
    {
        if ( document.purchaseOrderForm['purchaseOrder.poNumber'].value.length == 0 || document.purchaseOrderForm['purchaseOrder.poStatus'].value == '4' || document.purchaseOrderForm['purchaseOrder.poStatus'].value == '5' )
        {
            return;
        }
    }
    var paPo = document.getElementById("poErrors");
    paPo.innerHTML = "";

    if (printable() == true)
    {
        var poNumber = document.purchaseOrderForm['purchaseOrder.poNumber'].value;
        newWindow = window.open ('<%=chipTracContext%>/purchaseOrder.do?action=printerFriendly&poNumber='+poNumber,'optionsPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=yes,scrollbars=yes,width=700,height=700,resizable=yes,screenX=5,screenY=55,left=50,top=40');
        newWindow.focus();
    }
    else
    {
        paPo.innerHTML = "<li> Please save PO before Printing";
    }
}

function printable()
{
    var form = document.purchaseOrderForm;
    var count = document.purchaseOrderForm.count.value;
    var selectedIndexForPOType = 0;

    //This finds the defaultSelected index for the poType select.
    for (var i=0; i < form['purchaseOrder.poTypeId'].options.length; i++)
    {
        if ( form['purchaseOrder.poTypeId'].options[i].defaultSelected == true )
        {
            selectedIndexForPOType = i;
        }
    }

    if ( form['purchaseOrder.poTypeId'].options[selectedIndexForPOType].value !=
         form['purchaseOrder.poTypeId'].value )
    {
       return false;
    }

    if ( form['purchaseOrder.poDate'].defaultValue != form['purchaseOrder.poDate'].value )
    {
        return false;
    }

    if ( form['purchaseOrder.poHold'].defaultChecked != form['purchaseOrder.poHold'].checked )
    {
       return false;
    }

    var selectedIndexForPOStatus = 0;

    //This finds the defaultSelected index for the poStatus select.
    for (var i=0; i < form['purchaseOrder.poStatus'].options.length; i++)
    {
        if ( form['purchaseOrder.poStatus'].options[i].defaultSelected == true )
        {
            selectedIndexForPOStatus = i;
        }
    }

    if ( form['purchaseOrder.poStatus'].options[selectedIndexForPOStatus].value !=
         form['purchaseOrder.poStatus'].value )
    {
        return false;
    }

    var selectedIndexForCustomerID = 0;

    //This finds the defaultSelected index for the customerId select.
    for (var i=0; i < form['purchaseOrder.customerId'].options.length; i++)
    {
        if ( form['purchaseOrder.customerId'].options[i].defaultSelected == true )
        {
            selectedIndexForCustomerID = i;
        }
    }

    if ( form['purchaseOrder.customerId'].options[selectedIndexForCustomerID].value !=
         form['purchaseOrder.customerId'].value )
    {
        return false;
    }

    if ( form.displayShppAddId.value != form['purchaseOrder.shippToAddressId'].value )
    {
        return false;
    }

    if ( parseDec( form['purchaseOrder.tradeDiscount'].defaultValue, 2, '.' ) !=
         parseDec( form['purchaseOrder.tradeDiscount'].value, 2, '.' ) )
    {
        return false;
    }

    if ( parseDec( form['purchaseOrder.freight'].defaultValue, 2, '.' ) !=
         parseDec( form['purchaseOrder.freight'].value, 2, '.' ) )
    {
        return false;
    }

    if ( parseDec( form['purchaseOrder.miscellaneous'].defaultValue, 2, '.' ) !=
         parseDec( form['purchaseOrder.miscellaneous'].value, 2, '.' ) )
    {
        return false;
    }

    if ( parseDec( form['purchaseOrder.tax'].defaultValue, 2, '.' ) !=
         parseDec( form['purchaseOrder.tax'].value, 2, '.' ) )
    {
        return false;
    }

    if ( form['purchaseOrder.commentDescription'].defaultValue != form['purchaseOrder.commentDescription'].value )
    {
        return false;
    }

	var orgPartNumber = "";

    for( i = 0; i < count; i++ )
    {
		if( count > 1 )
		{
			orgPartNumber = form.orginalPartNumber[i].value;
		}
		else
		{
			orgPartNumber = form.orginalPartNumber.value ;
		}
		//if ( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].marketingPartNo'].defaultValue != form['purchaseOrder.purchaseOrderLineItemList[' + i + '].marketingPartNo'].value )
		if ( orgPartNumber != form['purchaseOrder.purchaseOrderLineItemList[' + i + '].marketingPartNo'].value )
		{
           return false;
		}

       if ( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].lineItemDescription'].defaultValue !=
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].lineItemDescription'].value )
       {
           return false;
       }

       if ( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].requiredDate'].defaultValue !=
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].requiredDate'].value )
       {
           return false;
       }

       if ( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].promisedDate'].defaultValue !=
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].promisedDate'].value )
       {
           return false;
       }

       if ( round ( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].requestedQuantity'].defaultValue )!=
            round ( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].requestedQuantity'].value ) )
       {
           return false;
       }

       if ( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].quantityCancelled'].defaultValue !=
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].quantityCancelled'].value )
       {
           return false;
       }

       if ( parseDec( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].unitCost'].defaultValue, 2, '.' ) !=
            parseDec( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].unitCost'].value, 2, '.' ) )
       {
            return false;
       }

       if ( parseDec( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].extendedCost'].defaultValue, 2, '.' ) !=
            parseDec( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].extendedCost'].value, 2, '.' ) )
       {
           return false;
       }

       if ( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].cancel'].defaultChecked !=
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].cancel'].checked )
       {
           return false;
       }
    }

    return true;
}

function assignNewPurchaseTaxScheduleOnChange(selectedItem)
{
    var form = document.purchaseOrderForm;
    var tempSelectedName = selectedItem.name;

    var tempStart = tempSelectedName.lastIndexOf("["); // Get the Starting index no of [
    var tempEnd = tempSelectedName.lastIndexOf("]");   // Get the Ending index no of ]

    var indexNo = parseInt (tempSelectedName.substring( tempStart + 1, tempEnd ) );

    // Assign the New Tax schedule Id to purchaseItemTaxScheduleId field.
    //form['purchaseOrder.purchaseOrderLineItemList[' + indexNo + '].purchaseItemTaxScheduleId'].value = form['purchaseOrder.purchaseAddressTaxScheduleId'].value;
}


function onLoad()
{  /*
    if ( document.purchaseOrderForm['purchaseOrder.poNumber'].value.length == 0 )
    {
        var form = document.purchaseOrderForm;
        var count = document.purchaseOrderForm.count.value;

        // Po related Fields.
        form['purchaseOrder.poHold'].disabled = true;
        form['purchaseOrder.vendorId'].disabled = true;
        form['purchaseOrder.poDate'].disabled = true;
        form['purchaseOrder.poTypeId'].disabled = true;
        form['purchaseOrder.tradeDiscount'].disabled = true;
        form['purchaseOrder.freight'].disabled = true;
        form['purchaseOrder.commentDescription'].disabled = true;
        form['purchaseOrder.miscellaneous'].disabled = true;
        form['purchaseOrder.tax'].disabled = true;
        form['purchaseOrder.customerId'].disabled = true;
        form['purchaseOrder.shippToAddressId'].disabled = true;

        if( form['purchaseOrder.poStatus'] != null )
        {
            form['purchaseOrder.poStatus'].disabled = true;
        }

        // Po Lineitem related Fields
        for( i = 0; i < count; i++ )
        {
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].marketingPartNo'].disabled = true;
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].manufacturingPartNo'].disabled = true;
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].lineItemDescription'].disabled = true;
            //form['purchaseOrder.purchaseOrderLineItemList[' + i + '].siteId'].disabled = true;
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].requestedQuantity'].disabled = true;
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].quantityCancelled'].disabled = true;
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].unitCost'].disabled = true;
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].extendedCost'].disabled = true;
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].poLineItemStatus'].disabled = true;
            // Added by SharatH on 20th May 04
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].requiredDate'].disabled = true;
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].promisedDate'].disabled = true;
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].cancel'].disabled = true; //added phani 22/04/04
        }
    }   */

    var form = document.purchaseOrderForm;
    var count = document.purchaseOrderForm.count.value;
    var shippedQty   = 0;
    var invoicedQty  = 0;
    var qtyShippedOrInvoiced = false;

    for( var i=0; i < count ; i++ )
    {
        shippedQty   = parseInt( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].quantityInvoiced'].value  );
        invoicedQty  = parseInt( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].quantityShipped'].value   );
        if ( shippedQty > 0 || invoicedQty > 0 )
        {
            qtyShippedOrInvoiced = true;
            break;
        }
    }
    if ( qtyShippedOrInvoiced == true )
    {
        form['purchaseOrder.poTypeId'].disabled = true;
        form['purchaseOrder.customerId'].disabled = true;
        form['purchaseOrder.shippToAddressId'].disabled = true;
    }
}


function formatAmountsOnLoad()
{
    var paAstrick = document.getElementById("poAstrick");
    var paShipadd = document.getElementById("poShipaddID");
    paAstrick.innerHTML = "";
    paShipadd.innerHTML = "";

    var form = document.purchaseOrderForm;
	var status1 = 1;
    var selectedCustomerId = form['purchaseOrder.customerId'].value.toLowerCase().trim();
    var addressesLength = form['purchaseOrder.shippToAddressId'].length;
    var paPo = document.getElementById("poErrors");
    paPo.innerHTML = "";
    var shippedQty   = 0;
    var invoicedQty  = 0;

    for (i = 0; i < form.count.value; i ++ )
    {
        form['purchaseOrder.purchaseOrderLineItemList[' + i + '].unitCost'].value = parseDec( round( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].unitCost'].value ), 2, '.' );

        if ( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].extendedCost'].value <= 99999999999999.99 )
        {
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].extendedCost'].value = parseDec( round( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].extendedCost'].value ), 2, '.' );
        }
        else
        {
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].extendedCost'].value = 99999999999999.99;
        }

        form['purchaseOrder.purchaseOrderLineItemList[' + i + '].requestedQuantity'].value = round( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].requestedQuantity'].value, 0 );
        form['purchaseOrder.purchaseOrderLineItemList[' + i + '].quantityCancelled'].value = round( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].quantityCancelled'].value, 0 );

        // disables whole line item entry if status is cancel
        //following "&&" condition by phani 06/04/2004, inorder avoid the disableness onload.
		if( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].cancel'].checked == true
            && ( parseInt ( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].requestedQuantity'].value ) ==
                 parseInt ( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].quantityCancelled'].value ) ) )
		{
			form['purchaseOrder.purchaseOrderLineItemList[' + i + '].marketingPartNo'].disabled = true;
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].manufacturingPartNo'].disabled = true;
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].lineItemDescription'].disabled = true;
            //form['purchaseOrder.purchaseOrderLineItemList[' + i + '].siteId'].disabled = true;
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].requestedQuantity'].disabled = true;
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].quantityCancelled'].disabled = true;
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].unitCost'].disabled = true;
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].extendedCost'].disabled = true;
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].poLineItemStatus'].disabled = true;
            // Added by SharatH on 20th May 04
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].requiredDate'].disabled = true;
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].promisedDate'].disabled = true;
		}

		status1 = form['purchaseOrder.purchaseOrderLineItemList[' + i + '].poLineItemStatus'].value;
        shippedQty   = parseInt( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].quantityInvoiced'].value  );
        invoicedQty  = parseInt( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].quantityShipped'].value   );

		//Disables cancel checkbox, If the Status is RECEIVED OR CLOSED OR
        //When the Status is RELEASED or Change Order, Check weather some Qty Shipped or Invoiced.
		if (  ( status1 == 4 ) || ( status1 == 5 ) || ( ( status1 == 2  || status1 == 3 ) && ( shippedQty > 0 || invoicedQty > 0 ) )  )
		{
                form['purchaseOrder.purchaseOrderLineItemList[' + i + '].cancel'].disabled = true;
		}
        //If PO Line Item Status is Received or Closed, Disabling all the fileds related to that Line Item.
		if  ( status1 == 4  ||  status1 == 5 )
		{
			form['purchaseOrder.purchaseOrderLineItemList[' + i + '].marketingPartNo'].disabled = true;
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].manufacturingPartNo'].disabled = true;
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].lineItemDescription'].disabled = true;
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].requestedQuantity'].disabled = true;
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].quantityCancelled'].disabled = true;
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].unitCost'].disabled = true;
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].extendedCost'].disabled = true;
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].poLineItemStatus'].disabled = true;
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].requiredDate'].disabled = true;
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].promisedDate'].disabled = true;
		}
        else if ( status1 == 2 || status1 == 3 )  //If PO Line Item Status is Released, Disabling Part Number to that Line Item.
        {
            //form['purchaseOrder.purchaseOrderLineItemList[' + i + '].manufacturingPartNo'].disabled = true;
            form['purchaseOrder.purchaseOrderLineItemList[' + i + '].marketingPartNo'].disabled = true;
        }
    }

    //added phani 28/04/04
    if ( form['purchaseOrder.subTotal'].value <= 99999999999999.99 )
    {
        form['purchaseOrder.subTotal'].value = parseDec( round( form['purchaseOrder.subTotal'].value ), 2, '.' );
    }
    else
    {
        form['purchaseOrder.subTotal'].value = 99999999999999.99;
    }

    //form['purchaseOrder.subTotal'].value = parseDec( round( form['purchaseOrder.subTotal'].value ), 2, '.' );
    form['purchaseOrder.tradeDiscount'].value = parseDec( round( form['purchaseOrder.tradeDiscount'].value ), 2, '.' );
    form['purchaseOrder.freight'].value = parseDec( round( form['purchaseOrder.freight'].value ), 2, '.' );
    form['purchaseOrder.miscellaneous'].value = parseDec( round( form['purchaseOrder.miscellaneous'].value ), 2, '.' );
    form['purchaseOrder.tax'].value = parseDec( round( form['purchaseOrder.tax'].value ), 2, '.' );
    //form['purchaseOrder.total'].value = parseDec( round( form['purchaseOrder.total'].value ), 2, '.' );

    //added phani 28/04/04
    if ( form['purchaseOrder.total'].value <= 99999999999999.99 )
    {
        form['purchaseOrder.total'].value = parseDec( round( form['purchaseOrder.total'].value ), 2, '.' );
    }
    else
    {
        form['purchaseOrder.total'].value = 99999999999999.99;
    }

    // Commented on 11th Feb 04.
    //form['purchaseOrder.remainingPoSubTotal'].value = parseDec( round( form['purchaseOrder.remainingPoSubTotal'].value ), 2, '.' );

    // Added for Drop-Ship type.
    if( form['purchaseOrder.poTypeId'].value != '2' )
    {
        paAstrick.innerHTML = "";
        paShipadd.innerHTML = "";
        form['purchaseOrder.customerId'].disabled = true;
        form['purchaseOrder.customerId'].value = "";
        form['purchaseOrder.shippToAddressId'].value = "0";
        form['purchaseOrder.shippToAddressId'].disabled = true;
        form.displayShppAddId.value = "0";
    }
    else
    {
        paAstrick.innerHTML = "*";
        paShipadd.innerHTML = "*";
        loadCustomerAddresses();
        //Assign customerId to customerId. Otherwise, when form is loaded customerName will be selected in the Customer Drop-Down.
        document.purchaseOrderForm['purchaseOrder.customerId'].value = document.purchaseOrderForm['purchaseOrder.customerId'].value;
        document.purchaseOrderForm.previousCustomerId.value = document.purchaseOrderForm['purchaseOrder.customerId'].value;
    }

    //Assign vendorId to vendorId. Otherwise, when form is loaded vendorName will be selected in the Vendor Drop-Down.
    document.purchaseOrderForm['purchaseOrder.vendorId'].value = document.purchaseOrderForm['purchaseOrder.vendorId'].value;
    document.purchaseOrderForm.previousVendorId.value = document.purchaseOrderForm['purchaseOrder.vendorId'].value;

    // Added by Devi on on 10 to display select when no value is there for shippToAddressId

    if( form.displayShppAddId.value == "" )
    {
        form.displayShppAddId.value ="0";
    }
    form['purchaseOrder.shippToAddressId'].value = form.displayShppAddId.value;


    if(typeof form['purchaseOrder.poHold'] != "undefined") //added by Krishna Prasad 21/09/2004
    {
        //added by phani 24/04/2004
        if( form['purchaseOrder.poHold'].checked == true )
        {
            for( i = 0; i < form.count.value; i++ )
            {
                form['purchaseOrder.purchaseOrderLineItemList[' + i + '].cancel'].disabled=true;
            }
        }
    }
    if( document.purchaseOrderForm['purchaseOrder.poStatus'] != null )
    {
        if( form['purchaseOrder.poStatus'].value == '4' || form['purchaseOrder.poStatus'].value == '5' )
        {
            form['purchaseOrder.poHold'].disabled = true;
            paPo.innerHTML = "<li> Purchase Order with Received or Closed status cannot be Modified.";
        }
    }

	if( form['purchaseOrder.poHold'].checked == true )
	{
		form['purchaseOrder.shippToAddressId'].disabled = true;
	}

    loadShipToAddress(); // Added by Krishna Prasad on 22-09-2004, to load the ShipToAddress in TextArea on startup.
}

function loadShipToAddress()   // Added by Krishna Prasad on 22-09-2004, to load the ShipToAddress in TextArea.
{

    var customerIdObj;
    var shipToAddressIdObj;
    var shipToAddressIdIndex;
    var form = document.purchaseOrderForm;
    var tempText = "";

	shipToAddressIdObj         = form['purchaseOrder.shippToAddressId']
    customerIdObj              = form['purchaseOrder.customerId']
    shipToAddressIdIndex       = shipToAddressIdObj.options[shipToAddressIdObj.selectedIndex].value;

    //Remove all the existing text in shipToAddress Textarea
    document.purchaseOrderForm.shipToAddress.value = '';

    //Adding the new values to the shipToAddress Textarea
    var selectedCustomerId;
    selectedCustomerId = customerIdObj.value.toLowerCase().trim();

    if( form['purchaseOrder.poTypeId'].value == '2' )
    {
        if( shipToAddressIdIndex != '0' )
        {
            for(var x = 0; x < customerIdsArray.length; x++ )
            {
                if( selectedCustomerId == customerIdsArray[x].toLowerCase().trim() )
                {
                    if( shipToAddressIdIndex.toLowerCase().trim() == customerAddressesArray[x].toLowerCase().trim() )
                    {
                        tempText = tempText + customerIdObj.options[customerIdObj.selectedIndex].text + "\n";
                        if ( customerContactPersonArray[x].trim().length > 0 )
                        {
                            tempText = tempText + customerContactPersonArray[x] + "\n";
                        }
                        if ( customerAddress1Array[x].trim().length > 0 )
                        {
                            tempText = tempText + customerAddress1Array[x] + "\n";
                        }
                        if ( customerAddress2Array[x].trim().length > 0 )
                        {
                            tempText = tempText + customerAddress2Array[x] + "\n";
                        }
                        if ( customerAddress3Array[x].trim().length > 0 )
                        {
                            tempText = tempText + customerAddress3Array[x] + "\n";
                        }
                        if ( customerCityArray[x].trim().length > 0 )
                        {
                            tempText = tempText + customerCityArray[x] + "\n";
                        }
                        temp = ""

                        if ( customerStateArray[x].trim().length > 0 )
                        {
                            temp = customerStateArray[x];
                        }
                        if ( customerZipCodeArray[x].trim().length > 0 )
                        {
                            if ( temp.length > 0 )
                            {
                                temp = temp + "-" +  customerZipCodeArray[x];
                            }
                            else
                            {
                                temp = customerZipCodeArray[x];
                            }
                        }
                        if ( customerCountryArray[x].trim().length > 0 )
                        {
                            if ( temp.length > 0 )
                            {
                                temp = temp + "," + customerCountryArray[x];
                            }
                            else
                            {
                                temp = customerCountryArray[x];
                            }
                        }

                        if ( temp.length > 0 )
                        {
                            tempText = tempText + temp + "\n";
                        }
                    }
                }
            }
        }
        document.purchaseOrderForm.shipToAddress.value = tempText ;
    }
    else
    {
        form.shipToAddress.value= form.hiddenShipToAddress.value;
    }
}

// Added for Drop-Ship Type
function loadCustomerAddresses()
{
    // This Function is called when the User changes the Customer Id.

    //Ship To Address ID Drop-Down should not effected, when we change from customerID to customerName in the Customer ID Drop-Drop
    if ( document.purchaseOrderForm.previousCustomerId.value == document.purchaseOrderForm['purchaseOrder.customerId'].value )
    {
        return;
    }
    else
    {
        document.purchaseOrderForm.previousCustomerId.value = document.purchaseOrderForm['purchaseOrder.customerId'].value;
    }

    var selectedCustomerId;
    var form = document.purchaseOrderForm;
    var temp = "";

    selectedCustomerId = form['purchaseOrder.customerId'].value.toLowerCase().trim();
    var addressesLength = form['purchaseOrder.shippToAddressId'].length;

     //Remove all the existing text in shipToAddress Textarea
    document.purchaseOrderForm.shipToAddress.value = '';

    //Remove all the existing select list contents in Customer Addresses List
    for( j = 0 ; j < addressesLength + 1 ; j++ )
    {
        form['purchaseOrder.shippToAddressId'][ 0 ] = null;
    }

    //Adding the new values to the Customer Addresses list
    form['purchaseOrder.shippToAddressId'].add(new Option( "----- Select -----", "0" ) );

    for( i = 0; i < customerIdsArray.length; i++ )
    {
        if( selectedCustomerId == customerIdsArray[i].toLowerCase().trim() )
        {
            form['purchaseOrder.shippToAddressId'].add(new Option( customerAddressesArray[i], customerAddressesArray[i] ) );
            if ( customerContactPersonArray[i].trim().length > 0 )
            {
                form['purchaseOrder.shippToAddressId'].add(new Option( customerContactPersonArray[i], customerAddressesArray[i]  ) );
            }
            if ( customerAddress1Array[i].trim().length > 0 )
            {
                form['purchaseOrder.shippToAddressId'].add(new Option( customerAddress1Array[i], customerAddressesArray[i] ) );
            }
            if ( customerAddress2Array[i].trim().length > 0 )
            {
                form['purchaseOrder.shippToAddressId'].add(new Option( customerAddress2Array[i], customerAddressesArray[i] ) );
            }
            if ( customerAddress3Array[i].trim().length > 0 )
            {
                form['purchaseOrder.shippToAddressId'].add(new Option( customerAddress3Array[i], customerAddressesArray[i] ) );
            }
            if ( customerCityArray[i].trim().length > 0 )
            {
                form['purchaseOrder.shippToAddressId'].add(new Option( customerCityArray[i], customerAddressesArray[i] ) );
            }
            temp = ""

            if ( customerStateArray[i].trim().length > 0 )
            {
                temp = customerStateArray[i];
            }
            if ( customerZipCodeArray[i].trim().length > 0 )
            {
                if ( temp.length > 0 )
                {
                    temp = temp + "-" +  customerZipCodeArray[i];
                }
                else
                {
                    temp = customerZipCodeArray[i];
                }
            }
            if ( customerCountryArray[i].trim().length > 0 )
            {
                if ( temp.length > 0 )
                {
                    temp = temp + "," + customerCountryArray[i];
                }
                else
                {
                    temp = customerCountryArray[i];
                }
            }

            if ( temp.length > 0 )
            {
                form['purchaseOrder.shippToAddressId'].add(new Option( temp, customerAddressesArray[i] ) );
            }

            form['purchaseOrder.shippToAddressId'].add(new Option( "", "0" ) );
        }
    }
    //For removing last unnecessary space.
    addressesLength = form['purchaseOrder.shippToAddressId'].length;
    if ( addressesLength > 2 )
    {
        form['purchaseOrder.shippToAddressId'].remove( addressesLength - 1);
    }


    // Enable Addresses Drop Down.
    changeCustomerId();
}

function changePoType()
{
    // This function is called when the user changes the PO Type.
    var form = document.purchaseOrderForm;
    var paAstrick = document.getElementById("poAstrick");
    var paShipadd = document.getElementById("poShipaddID");
    paAstrick.innerHTML = "";
    paShipadd.innerHTML = "";

    if( form['purchaseOrder.poTypeId'].value == '2' )
    {
       paAstrick.innerHTML = "*";
       paShipadd.innerHTML = "*";
       form['purchaseOrder.customerId'].disabled = false;
       form.shipToAddress.value= '';
       form.shipToAddress.disabled = true;
    }
    else
    {
        form['purchaseOrder.customerId'].value = '';
        form['purchaseOrder.customerId'].disabled = true;
        form['purchaseOrder.shippToAddressId'].disabled = true;
        form['purchaseOrder.shippToAddressId'].value ='0';
        form.shipToAddress.value= form.hiddenShipToAddress.value;
        form.shipToAddress.disabled = true;
    }
}
function changeCustomerId()
{
    // This function is called when the user changes the Customer ID.
    var form = document.purchaseOrderForm;

    if( form['purchaseOrder.customerId'].value != '' && form['purchaseOrder.customerId'].value != '-1' )
    {
       form['purchaseOrder.shippToAddressId'].disabled = false;
    }
    else
    {
        form['purchaseOrder.shippToAddressId'].value = '0';
        form['purchaseOrder.shippToAddressId'].disabled = true;
    }
}
function changeStatus( i, chekbox )
{
    var paPo = document.getElementById("poErrors");
    var paLineItem = document.getElementById("lineItemErrors");
    paPo.innerHTML = "";
    paLineItem.innerHTML = "";

    var form = document.purchaseOrderForm;
	var flag = chekbox.checked;
    var chk=0;

    var requestedQty = parseInt( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].requestedQuantity'].value );
    var cancelledQty = parseInt( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].quantityCancelled'].value );
    var shippedQty   = parseInt( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].quantityInvoiced'].value  );
    var invoicedQty  = parseInt( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].quantityShipped'].value   );
    var poLineItemStatus = form['purchaseOrder.purchaseOrderLineItemList[' + i + '].poLineItemStatus'].value;

    if(   ( ( requestedQty == cancelledQty ) && ( poLineItemStatus == 1 || poLineItemStatus == 6 ) ) ||
          ( ( requestedQty == cancelledQty ) && ( poLineItemStatus == 2 || poLineItemStatus== 3 ) && ( shippedQty == 0 && invoicedQty == 0 ) )  )
    {
        //When Line Item Status is NEW or CANCELLED, Then only we have to make it enabled.
        if ( poLineItemStatus == 1 || poLineItemStatus == 6 )
        {
	        form['purchaseOrder.purchaseOrderLineItemList[' + i + '].marketingPartNo'].disabled = flag;
        }
	    //form['purchaseOrder.purchaseOrderLineItemList[' + i + '].manufacturingPartNo'].disabled = flag;
		form['purchaseOrder.purchaseOrderLineItemList[' + i + '].lineItemDescription'].disabled = flag;
	    form['purchaseOrder.purchaseOrderLineItemList[' + i + '].requestedQuantity'].disabled = flag;
		form['purchaseOrder.purchaseOrderLineItemList[' + i + '].quantityCancelled'].disabled = flag;
	    form['purchaseOrder.purchaseOrderLineItemList[' + i + '].unitCost'].disabled = flag;
		form['purchaseOrder.purchaseOrderLineItemList[' + i + '].extendedCost'].disabled = flag;
        form['purchaseOrder.purchaseOrderLineItemList[' + i + '].requiredDate'].disabled = flag;
        form['purchaseOrder.purchaseOrderLineItemList[' + i + '].promisedDate'].disabled = flag;
		chk=1;
	}
    if (  ( chk == 0 ) && ( flag == true ) )
	{
        paLineItem.innerHTML =  "<li>" + "Requested Quantity and Quantity Cancelled should be same to Cancel Line Item No"+( i + 1 );
    }
}

function onKeyPressQtyCanc( i )
{
    var form = document.purchaseOrderForm;
    var paLineItem = document.getElementById("lineItemErrors");
    paLineItem.innerHtml = '';
    var requestedQty = parseInt( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].requestedQuantity'].value );
    var cancelledQty = parseInt( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].quantityCancelled'].value );
    var shippedQty   = parseInt( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].quantityInvoiced'].value  );
    var invoicedQty  = parseInt( form['purchaseOrder.purchaseOrderLineItemList[' + i + '].quantityShipped'].value   );
    var poLineItemStatus = form['purchaseOrder.purchaseOrderLineItemList[' + i + '].poLineItemStatus'].value;

    /*
      Disabling this PO Line Item Fields and Checking cancel CheckBox done
      1.When Qty Req equal to Qty Cancel and Line Item is in New Or Cancelled State and Qty Req is greater than 0
      2.When Qty Req equal to Qty Cancel and Line Item is in Released Or Change Order State and Qty Ship, invoice is 0
    */
    if(   ( ( requestedQty == cancelledQty ) && ( poLineItemStatus == 1 || poLineItemStatus == 6 ) && ( requestedQty > 0 ) ) ||
          ( ( requestedQty == cancelledQty ) && ( poLineItemStatus == 2 || poLineItemStatus== 3 ) && ( shippedQty == 0 && invoicedQty == 0 ) )  )
    {
        form['purchaseOrder.purchaseOrderLineItemList[' + i + '].marketingPartNo'].disabled = true;
	    form['purchaseOrder.purchaseOrderLineItemList[' + i + '].manufacturingPartNo'].disabled = true;
		form['purchaseOrder.purchaseOrderLineItemList[' + i + '].lineItemDescription'].disabled = true;
	    form['purchaseOrder.purchaseOrderLineItemList[' + i + '].requestedQuantity'].disabled = true;
		form['purchaseOrder.purchaseOrderLineItemList[' + i + '].quantityCancelled'].disabled = true;
	    form['purchaseOrder.purchaseOrderLineItemList[' + i + '].unitCost'].disabled = true;
		form['purchaseOrder.purchaseOrderLineItemList[' + i + '].extendedCost'].disabled = true;
        form['purchaseOrder.purchaseOrderLineItemList[' + i + '].requiredDate'].disabled = true;
        form['purchaseOrder.purchaseOrderLineItemList[' + i + '].promisedDate'].disabled = true;
		form['purchaseOrder.purchaseOrderLineItemList[' + i + '].cancel'].checked = true;
        paLineItem.innerHTML = '';
        //here, Quantity requested and Quantity cancelled are disable, so their onblur event is not firing.
        //so, explicitly calling for calculating the extended cost.
        calculateTotal ();
    }
}

function purchasingDateEntry()
{
    if( document.purchaseOrderForm['purchaseOrder.poStatus'] != null )
    {
        if ( document.purchaseOrderForm['purchaseOrder.poNumber'].value.length == 0 || document.purchaseOrderForm['purchaseOrder.poStatus'].value == '4' || document.purchaseOrderForm['purchaseOrder.poStatus'].value == '5' )      //added by phani 30/04/04
        {
            return;
        }
    }
    var form = document.purchaseOrderForm;
    var requistionDate = document.purchaseOrderForm['purchaseOrder.poDate'].value;
    var hold = form['purchaseOrder.poHold'].checked;

    var paPo = document.getElementById("poErrors");
    paPo.innerHTML = "";

    if( !chkDate( requistionDate, "Purchase Order Date", 'Y' ) )
    {
        paPo.innerHTML = errMsg;
    } else
    {
        newWindow = window.open ('<%=chipTracContext%>/purchaseOrder.do?action=purchasingDateEntry&purchaseOrder.purchaseOrderDate='+requistionDate+'&purchaseOrder.poHold='+hold,'optionsPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=yes,scrollbars=no,width=700,height=380,left=150,top=100,resizable=yes');
        newWindow.focus();
    }
}

function checkLength(element, size)
{
    if(	element.value.length >= size )
	{
		event.returnValue = false;
	}
}

// Added by Sharath for Checking Vendor Id is selected or not.
function checkForVendorID()
{
    var paLineItem = document.getElementById("lineItemErrors");
    paLineItem.innerHtml = '';

    if( document.purchaseOrderForm['purchaseOrder.vendorId'].value == '' )
    {
        paLineItem.innerHTML = " <li> Please Select Vendor Name";
        document.purchaseOrderForm['purchaseOrder.vendorId'].focus();
    }
}
/*
function siteEntry( purchaseOrderLineItemNo )
{
    var form = document.purchaseOrderForm;

    //If PO Line Item Status is Received, Chagne Order, Closed or Received, We should not change Site ID.
    if ( form['purchaseOrder.purchaseOrderLineItemList[' + purchaseOrderLineItemNo + '].poLineItemStatus'].value != 2 && form['purchaseOrder.purchaseOrderLineItemList[' + purchaseOrderLineItemNo + '].poLineItemStatus'].value != 3 && form['purchaseOrder.purchaseOrderLineItemList[' + purchaseOrderLineItemNo + '].poLineItemStatus'].value != 4 && form['purchaseOrder.purchaseOrderLineItemList[' + purchaseOrderLineItemNo + '].poLineItemStatus'].value != 5 )
    {
        var paLineItem = document.getElementById("lineItemErrors");
        paLineItem.innerHtml = '';

        var vendorID   = document.purchaseOrderForm['purchaseOrder.vendorId'].value;
        var itemNumber = form['purchaseOrder.purchaseOrderLineItemList[' + purchaseOrderLineItemNo + '].manufacturingPartNo'].value;
        //If Part Number Not Selected, Giving Error Message to Select Part Number ID
        if( itemNumber == '' )
        {
            paLineItem.innerHTML = " <li> Please Select Part Number in Line Item No " + parseInt(purchaseOrderLineItemNo + 1);
            form['purchaseOrder.purchaseOrderLineItemList[' + purchaseOrderLineItemNo + '].manufacturingPartNo'].focus();
            return;
        }
        //var selectedSiteID = form['purchaseOrder.purchaseOrderLineItemList[' + purchaseOrderLineItemNo + '].siteId'].value
        //newWindow = window.open //('<%=chipTracContext%>/purchaseOrder.do?action=purchaseOrderSiteEntry&purchaseOrderLineItemNo='+purchaseOrderLineItemNo+'&itemNumber='+itemNumber+'&vendorID='+vendorID+'&selectedSiteID='+selectedSiteID,'optionsPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=yes,scrollbars=no,width=500,height=150,left=300,top=200,resizable=yes');
        newWindow.focus();
    }
}
*/
function sendMail()
{
    var poNumber = document.purchaseOrderForm['purchaseOrder.poNumber'].value;
    newWindow = window.open ('<%=chipTracContext%>/poSendMail.do?poNumber=' + poNumber ,'sendMailPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=yes,width=800,height=480,resizable=yes');
    newWindow.focus();
}
//Print Friendly Screen Calls refresh method.
function refresh()
{
    self.location.replace ( '<%= request.getRequestURL() + "?" + request.getQueryString() %>' );
}
</SCRIPT>
</HEAD>
<BODY bgColor='#ffffff' leftMargin='0' topMargin='0' marginheight='0' marginwidth='0' onload="javascript:formatAmountsOnLoad();javascript:onLoad();">
<!-- Top Header Start-->
<%@include file="/jsp/includes/header.jsp"  %>
<!-- Top Header End-->
<TABLE cellSpacing=0 cellPadding=0 width="100%" border="0" bordercolor="blue">
  <TBODY>
  <TR>
	<TD width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>

<!-- Side Navigation start -->

<%@include file="/jsp/finance/purchase_order_menu.jsp" %>

</TD>
<!-- end of the side navigations -->

<TD bgcolor="#ffffff">
<IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></TD>
<TD bgcolor="#ffffff"><IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></TD>
<TD valign="top" width="100%">

<!-- SiteMap Tag --><%--
<chiptrack:sitemap styleClass="NArialS"/>--%><%
    String functionalityString = "";

    if ( request.getAttribute("actiontype") != null && ((String)request.getAttribute("actiontype")).trim().equalsIgnoreCase("new") )
    {
        functionalityString = Functionality.PURCHASE_ORDER;
    }
    else
    {
        functionalityString = Functionality.CHANGE_PURCHASE_ORDER;
    }

%><chiptrack:permission functionality='<%=functionalityString%>'
    action='<%=User.USER_ACTION_MODIFY%>' styleClass="NArialL" >
</chiptrack:permission>


<IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width=500 border=0>
<!-- from here your body starts -->
			<TABLE BORDER="0" WIDTH="100%">

				<TR>
					<TD WIDTH="100%">
            <html:form name="purchaseOrderForm" action="/purchaseOrder.do" method="post" type="com.scalar.chiptrack.finance.purchaseorder.forms.PurchaseOrderForm">
            <input type= "hidden" name = "action" value="">
            <input type="hidden" name="statusType" value="<%= request.getParameter("statusType") %>">
            <input type="hidden" name="previousCustomerId" value=""/>
            <input type="hidden" name="previousVendorId" value=""/>
            <TABLE BORDER="0" WIDTH="100%" HEIGHT="175%">
				<TR>
					<TD WIDTH="100%">
						<TABLE BORDER="0" WIDTH="100%">
							<TR>
								<TD WIDTH="100%" class="NArialW">
									<P ALIGN="LEFT">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                    Purchase Order
								</TD>
							</TR>
                            <TR>
                                 <TD WIDTH="100%" align = "">
                                <logic:equal name="action" value="edit" >
		                                <font align=right class="NArialS">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                        <a href="javascript:sendMail();"  onMouseOver="window.status='Click to Mail the Purchase Order';return true" onMouseOut="window.status='';return true" ><b>[E-mail this Purchase Order]</b></a>&nbsp;&nbsp; &nbsp;&nbsp;
										<font align=right class="NArialS">
											<a href="javascript:printableVersion();" onMouseOver="window.status='Click to Printer-Friendly Version';return true" onMouseOut="window.status='';return true"><img src='<%=chipTracContext%>/jsp/includes/images/spacer.gif' border='0' height='1' width='1'><b>[Printer-Friendly Version]</b></a></font>
											<!--A HREF="javascript:printableVersion()" onmouseover="window.status='Click here for Printable version';return true" onmouseout="window.status='';return true">Click here</A>&nbsp;for Printable version-->
										<chiptrack:restrictedLink functionality="<%=functionalityString%>"
											action="<%=User.USER_ACTION_MODIFY%>"href="javascript:printableVersion();" onmouseover="window.status='Click here for Printable Version';return true" onmouseout="window.status='';return true">
											<!--IMG SRC="<%=chipTracContext%>/jsp/includes/images/printer_friendly_version.gif" ALIGN="BOTTOM" BORDER="0" -->
										</chiptrack:restrictedLink>
                                </logic:equal>
                                </TD>
                            </TR>
                            <TR>
                                <TD><chiptrack:info styleClass="NArialL" /></TD>
                            </TR>
						</TABLE>
                        <BR>
                        <nested:define id="purchaseOrderLocal" property="purchaseOrder" type="PurchaseOrder" />
                        <nested:nest property="purchaseOrder">
                        <!-- To Display Message, If PO is on HOLD and the User doesn't have permission to Approve Purchase Order  -->
                        <%
                            boolean disableCheckBox = false;
                            if (user != null) {
                                disableCheckBox = !user.isActionAllowed( Functionality.APPROVE_PURCHASE_ORDER, User.USER_ACTION_MODIFY );
                            }
                            if ( disableCheckBox )
                            {
                          %><nested:equal property="poHold" value="true">
                            <table border='0' bordercolor='#FFFFFF'>
                                <tr class='NArialL'>
                                <td align='left'><font color='blue'><bold><li>You don't have permission to Approve Purchase Order</bold></font></td>
                                </tr>
                            </table>
                            </nested:equal><%
                            }
                      %><TABLE BORDER="0" WIDTH="80%" CLASS="NArialL">
                            <TR>
                                <TD colspan = "9"><FONT id="poErrors" class="NArialL" color="red"></FONT></TD>
                       		<TR>
								<TD WIDTH="1%">&nbsp;</TD>
								<TD WIDTH="14%">PO Number:</TD>
								<!--TD WIDTH="1%">&nbsp;</TD-->
								<TD WIDTH="17%" align = "left">
                                    <nested:text property="poNumber" styleClass="txfield" size="21" maxlength="17" disabled="true" readonly="true"/>
                                </TD>
								<TD WIDTH="4%">&nbsp;</TD>
								<TD WIDTH="14%">Type:&nbsp;<font color ="red" class="NArialL">*</font></TD>
								<!--TD WIDTH="1%">&nbsp;</TD-->
								<TD WIDTH="30%">
                                    <nested:hidden property="poTypeLabel" />
									<nested:select property="poTypeId" styleClass="txfield" disabled="<%=enableOrDisable%>" onchange="javascript:changePoType();" >
                                        <%--<html:option value="" >----- Select -----</html:option>--%>
                                        <html:options collection = "poTypeList" property="value" labelProperty="label"/>
                                    </nested:select><%--
                                    <% if( request.getParameter("action") != null && request.getParameter("action").equalsIgnoreCase("edit") ) { %>
                                            <chiptrack:restrictedLink functionality='<Functionality.APPROVE_PURCHASE_ORDER>' action='<%=User.USER_ACTION_MODIFY%>' styleClass="NArialL" href="#" >
                                            &nbsp;&nbsp;&nbsp;<nested:checkbox property="poHold" value = "true" styleClass="txfield" onclick="javascript:validateHold();javascript:hold()" />Hold
                                            </chiptrack:restrictedLink>
                                    <% } else if( request.getAttribute("action") != null && request.getAttribute("action").toString().equalsIgnoreCase("edit") ) { %>
                                            <chiptrack:restrictedLink functionality='<Functionality.APPROVE_PURCHASE_ORDER>' action='<%=User.USER_ACTION_MODIFY%>' styleClass="NArialL" href="#" >
                                            &nbsp;&nbsp;&nbsp;<nested:checkbox property="poHold" value = "true" styleClass="txfield" onclick="javascript:validateHold();javascript:hold()" />Hold
                                            </chiptrack:restrictedLink>
                                    <% } else  { %>
                                           <nested:hidden property="poHold"/>
                                    <% } %>--%>
                                    <!-- If user doesn't have permission to Approve Purchase Order, Disabling the HOLD Check Box. -->
                                    <logic:equal name="action" value="edit">
                                        &nbsp;&nbsp;&nbsp;<nested:checkbox property="poHold" value = "true" disabled="<%=disableCheckBox%>" styleClass="txfield" onclick="javascript:validateHold();javascript:hold()" />Hold
                                    </logic:equal>
                                    <logic:notEqual name="action" value="edit">
                                        <nested:hidden property="poHold"/>
                                    </logic:notEqual>
                                </TD>
								<TD WIDTH="14%">&nbsp;</TD>
							</TR>
							<TR>
								<TD WIDTH="1%">&nbsp;</TD>
								<TD WIDTH="14%">Vendor Name:&nbsp;<font color ="red" style="arial">*</font></TD>
								<!--TD WIDTH="1%">&nbsp;</TD-->
								<TD WIDTH="17%">

                                <logic:equal name="action" value="edit" >
                                    <nested:select property="vendorId" styleClass="txfield" disabled="true">
                                        <html:options collection = "vendorsList" property="label" labelProperty="value"/>
                                    </nested:select>
                                </logic:equal>

                                <logic:notEqual name="action" value="edit" >
                                    <nested:select property="vendorId" styleClass="txfield" disabled="<%=enableOrDisable%>" onchange="javascript:vendorOnChange()">
                                        <html:options collection = "vendorsList" property="label" labelProperty="value"/>
                                    </nested:select>
                                </logic:notEqual>

								</TD>
								<TD WIDTH="4%">&nbsp;</TD>
								<TD WIDTH="14%">PO Date:&nbsp;<font color ="red" style="arial">*</font></TD>
								<!--TD WIDTH="1%">&nbsp;</TD-->
								<TD WIDTH="25%">
									<nested:text property="poDate" size ="11" styleClass="txField" maxlength="10" disabled="<%=enableOrDisable%>"/>&nbsp;
                                    <%--<a href="javascript:purchasingDateEntry()" onmouseover="window.status='Click here To add Purchasing Date Entry';return true" onmouseout="window.status='';return true">
                                        <IMG SRC="<%=chipTracContext%>/jsp/includes/images/arrow.gif" WIDTH="14" HEIGHT="15" ALIGN="BOTTOM" BORDER="0"></a>--%>
								</TD>
								<TD WIDTH="14%">&nbsp;</TD>
							</TR>

                            <TR>
                                    <TD WIDTH="1%">&nbsp;</TD>
                                    <TD WIDTH="15%">Customer Name:&nbsp;<FONT id="poAstrick" styleClass="NArialL" color="red" size="1"></FONT></TD>
                                    <!--TD WIDTH="1%">&nbsp;</TD-->
                                    <TD WIDTH="17%">
                                        <nested:select property="customerId" styleClass="txfield" onchange = "javascript:loadCustomerAddresses();" disabled="<%=enableOrDisable%>">
                                             <html:options collection = "customerIdList" property="value" labelProperty="label"/>
                                         </nested:select>
                                    </TD>
                                    <TD WIDTH="4%">&nbsp;</TD>
                                    <TD WIDTH="14%" nowrap>Ship To Addresses:&nbsp;<FONT id="poShipaddID" styleClass="NArialL" color="red" size="1"></FONT></TD>
                                   <!--TD WIDTH="1%">&nbsp;</TD-->
                                    <TD WIDTH="30%">
                                        <input type="hidden" name="displayShppAddId" value="<nested:write property = "shippToAddressId" />"/>
                                        <nested:select property="shippToAddressId" styleClass="txfield" disabled="<%=enableOrDisable%>" onchange = "javascript:loadShipToAddress()">
                                            <option value="0">---- Select ---- </option>
                                        </nested:select>
                                    </TD>
                                    <TD WIDTH="14%">&nbsp;</TD>
                                </TR>

							<TR>
								<TD WIDTH="1%">&nbsp;</TD>
								<TD WIDTH="14%">Requistion Date:&nbsp;</TD>
								<TD WIDTH="17%">
                                <nested:text property="requistionDate" size ="11" styleClass="txField" maxlength="10" disabled="<%=enableOrDisable%>"/>								</TD>
								<TD rowspan="4" WIDTH="4%">&nbsp;</TD>
								<TD rowspan="4" WIDTH="14%">Ship To Address:&nbsp;</TD>
								<TD rowspan="4" WIDTH="25%">
									<textarea name="shipToAddress" rows="8" cols="35" class="txfield" disabled="true"></textarea>
                                    <% String customerAddress = purchaseOrderLocal.getFormattedCustomerAddressObjAsString( (CustomerAddress) session.getAttribute("standardTypeCustomerDetails") ); %>
                                    <textarea name="hiddenShipToAddress" style="DISPLAY: none;"><%=customerAddress%></textarea>
								</TD>
								<TD rowspan="4" WIDTH="14%">&nbsp;</TD>
							</TR>


							<TR>
								<TD WIDTH="1%">&nbsp;</TD>
								<TD WIDTH="14%">Required Date:&nbsp;</TD>
								<TD WIDTH="17%">
                                <nested:text property="requiredDate" size ="11" styleClass="txField" maxlength="10" disabled="<%=enableOrDisable%>"/>								</TD>
							</TR>

							<TR>
								<TD WIDTH="1%">&nbsp;</TD>
								<TD WIDTH="14%">Promised Date:&nbsp;</TD>
								<TD WIDTH="17%">
                                <nested:text property="promisedDate" size ="11" styleClass="txField" maxlength="10" disabled="<%=enableOrDisable%>"/>								</TD>
							</TR>

							<TR>
								<TD WIDTH="1%">&nbsp;</TD>
								<TD WIDTH="14%" nowrap>Promised Ship Date:&nbsp;</TD>
								<TD WIDTH="17%">
                                <nested:text property="promisedShipDate" size ="11" styleClass="txField" maxlength="10" disabled="<%=enableOrDisable%>"/>								</TD>
							</TR>
                            <logic:equal name="action" value="edit" >
							<TR>
								<TD WIDTH="1%">&nbsp;</TD>
								<TD WIDTH="14%">Last Edited Date:&nbsp;</TD>
								<TD WIDTH="17%"><nested:text property="lastEditedDate" styleClass="txfield" size="11" disabled="true" /></TD>
								<TD WIDTH="4%">&nbsp;</TD>
								<TD WIDTH="14%">Last Released Date:&nbsp;</TD>
								<TD WIDTH="25%"><nested:text property="lastPrintedDate" styleClass="txfield" size="11" disabled="true" /></TD>
								<TD WIDTH="14%">&nbsp;</TD>
							</TR>

                            <!-- Show Po Status Drop Down if the user is Editing a PO -->
                            <TR>
                                <TD WIDTH="1%">&nbsp;</TD>
                                <TD WIDTH="15%">PO Status:</TD>
                              <!--TD WIDTH="1%">&nbsp;</TD-->
                                <TD WIDTH="17%">
                                    <nested:hidden property="poStatusLabel" />
                                    <nested:select property="poStatus" styleClass="txfield" disabled="true" >
                                        <html:options collection = "poLineItemStatusList" property="value" labelProperty="label" />
                                    </nested:select>
                                </TD>
                                <TD WIDTH="1%">&nbsp;</TD>
                                <TD WIDTH="15%">&nbsp;</TD>
                                <TD WIDTH="1%">&nbsp;</TD>
                                <TD WIDTH="31%">&nbsp;</TD>
                                <TD WIDTH="15%">&nbsp;</TD>
                            </TR>
                            </logic:equal>

							<TR>
								<TD WIDTH="100%" colspan="9">&nbsp;</TD>
							</TR>
						</TABLE>
                        <BR>
						<BR>

                        <TABLE BORDER="0" WIDTH="100%" CLASS="NArialL">
                            <TR>
                                <TD WIDTH = "100%" COLSPAN="11">
                                    <FONT id="lineItemErrors" styleClass="NArialL" color="red"></FONT>
                                </TD>
                            </TR>
							<TR>
								<TD WIDTH="4%" HEIGHT="26" ALIGN="CENTER" BGCOLOR="#993333">
									<P ALIGN="CENTER">&nbsp;<FONT COLOR="white">Line Item</FONT>
								</TD>
								<TD WIDTH="10%" HEIGHT="26" ALIGN="CENTER" BGCOLOR="#993333">
									<P ALIGN="CENTER"><FONT COLOR="white">Part Number</FONT>
								</TD>
								<TD WIDTH="10%" HEIGHT="26" BGCOLOR="#993333">
									<P ALIGN="CENTER"><FONT COLOR="white">Vendor Part Number</FONT>
								</TD>
                                <TD WIDTH="16%" HEIGHT="26" ALIGN="CENTER" BGCOLOR="#993333">
									<P ALIGN="CENTER"><FONT COLOR="white">Description</FONT>
								</TD>

                                <TD WIDTH="10%" HEIGHT="26" ALIGN="CENTER" BGCOLOR="#993333">
									<P ALIGN="CENTER"><FONT COLOR="white">Required Date</FONT>
								</TD>
                                <TD WIDTH="10%" HEIGHT="26" ALIGN="CENTER" BGCOLOR="#993333">
									<P ALIGN="CENTER"><FONT COLOR="white">Promised Date</FONT>
								</TD>
                                <!-- TD WIDTH="10%" HEIGHT="26" ALIGN="CENTER" BGCOLOR="#993333">
									<P ALIGN="CENTER"><FONT COLOR="white">Site</FONT>
								</TD -->
								<TD WIDTH="10%" HEIGHT="16" ALIGN="CENTER" BGCOLOR="#993333">
									<P ALIGN="CENTER"><FONT COLOR="white">Requested Quantity</FONT>
								</TD>
								<TD WIDTH="10%" HEIGHT="16" ALIGN="CENTER" BGCOLOR="#993333">
									<P ALIGN="CENTER"><FONT COLOR="white">Quantity Cancelled</FONT>
								</TD>
								<TD WIDTH="10%" HEIGHT="16" ALIGN="CENTER" BGCOLOR="#993333">
									<P ALIGN="CENTER"><FONT COLOR="white">Unit Cost</FONT>
								</TD>
								<TD WIDTH="10%" HEIGHT="26" ALIGN="CENTER" BGCOLOR="#993333">
									<P ALIGN="CENTER"><FONT COLOR="white">Extended Cost</FONT>
								</TD>
                                <TD WIDTH="10%" HEIGHT="26" ALIGN="CENTER" BGCOLOR="#993333">
									<P ALIGN="CENTER"><FONT COLOR="white">Status</FONT>
								</TD>
								<TD WIDTH="10%" HEIGHT="26" ALIGN="CENTER" BGCOLOR="#993333">
									<P ALIGN="CENTER"><FONT COLOR="white">Cancel</FONT>
								</TD>
							</TR>
                            <nested:iterate property="purchaseOrderLineItemList" type="com.scalar.chiptrack.finance.purchaseorder.PurchaseOrderLineItem" >
							<TR>
								<TD WIDTH="4%" ALIGN="CENTER" BGCOLOR="#DEE1E2">
									<P ALIGN="CENTER">&nbsp;
                                    <nested:write property="poIndex"/>
                                    <nested:hidden property="poIndex" />

                                    <nested:hidden property="poLineItemSequenceNo"/>
                                    <!-- Hidden field stores the no of Line items available for a Purchase Order -->
                                    <nested:hidden property="lineItemCount" />
								</TD>
								<TD WIDTH="10%" ALIGN="CENTER" BGCOLOR="#DEE1E2">
									<CENTER>
									<P>
                                    <bean:define id="index" value="0"/>
                                    <nested:select property="marketingPartNo" styleClass="txfield" onchange="javascript:getPartDescription(this)" disabled="<%=enableOrDisable%>" onfocus = "javascript:checkForVendorID();">
                                        <!--html:option value="" >----- Select -----<!--/html:option-->
                                        <html:options collection = "marketingPartNoList" property="label" labelProperty="value" />
                                    </nested:select>
									<input type="hidden" name="orginalPartNumber" value="<nested:write property="marketingPartNo"/>" >
                                    </CENTER>
								</TD>
								<TD WIDTH="10%" BGCOLOR="#DEE1E2">
									<CENTER>
									<P>
									<!-- The property is disabled by default because when the Vendor Part number is removed the
									PO is not loading in GP	-->
                                    <nested:text property="manufacturingPartNo" styleClass="txfield" disabled="true" onkeypress="javascript:checkLength(this, 30)"/>
                                    </CENTER>
								</TD>
                                <TD WIDTH="16%" ALIGN="CENTER" BGCOLOR="#DEE1E2">
									<CENTER>
									<P><nested:textarea property="lineItemDescription" styleClass="txField" disabled="<%=enableOrDisable%>" onkeypress="javascript:checkLength(this, 50)"/>
                                    </CENTER>
								</TD>

                                <TD WIDTH="10%" ALIGN="CENTER" BGCOLOR="#DEE1E2">
									<CENTER>
									<P><nested:text property="requiredDate" styleClass="txfield" maxlength="10" size="11" disabled="<%=enableOrDisable%>"/>
                                    </CENTER>
								</TD>

                                <TD WIDTH="10%" ALIGN="CENTER" BGCOLOR="#DEE1E2">
									<CENTER>
									<P><nested:text property="promisedDate" styleClass="txfield" maxlength="10" size="11" disabled="<%=enableOrDisable%>"/>
                                    </CENTER>
								</TD>
                                <!--TD WIDTH="10%" ALIGN="CENTER" BGCOLOR="#DEE1E2">
									<CENTER>
									<P>< n e s t e d : t e x t  p r o p e r t y = " s i t e I d"   s t y l e Cl a s s= " t x f ie l d" maxlength="10" size="11" disabled="true"/>&nbsp; <a href="javascript:siteEntry(<%= i %>)" onmouseover="window.status='Click here To select Site';return true" onmouseout="window.status='';return true">
                                            <IMG SRC="<%=chipTracContext%>/jsp/includes/images/arrow.gif" WIDTH="14" HEIGHT="15" ALIGN="BOTTOM" BORDER="0"></a>
                                    </CENTER>
								</TD-->
                                <!--TD WIDTH="10%" ALIGN="CENTER" BGCOLOR="#DEE1E2">
									<CENTER>
									<P>
                                    <!--n e s t e d : s e l e c t   pr o p e r t y = " s it e I d" styleClass="txfield" disabled="<%//=enableOrDisable%>" >
                                       <!-- h t m l : o p t i o n s   c o l l e c t i o n   =   " s i t e L i s t "   pr operty="value" labelProperty="label"  />
                                    <!--/ n e s t e d :s e l e c t>
                                    </CENTER>
								</TD-->
								<!-- added onkeypress for quantityShipped, quantityInvoiced etc. fields: Phani
								on 23th March 2004	-->
								<TD WIDTH="10%" ALIGN="CENTER" BGCOLOR="#DEE1E2">
									<CENTER>
                                    <% String cancelledString = "javascript:onKeyPressQtyCanc(" + i + ")"; %>
									<P><nested:text property="requestedQuantity" styleClass="valuetxfield" size="10" onblur="javascript:calculateTotal()" maxlength="9" disabled="<%=enableOrDisable%>" onchange="<%=cancelledString%>" onkeypress="javascript:numericFieldKeyPress( this )"/>
                                    </CENTER>
								</TD>
                                <nested:hidden property="quantityInvoiced"/>
                                <nested:hidden property="quantityShipped"/>
								<TD WIDTH="10%" ALIGN="CENTER" BGCOLOR="#DEE1E2">
									<CENTER>
									<P>
                                    <% cancelledString = "javascript:onKeyPressQtyCanc(" + i + ")"; %>
                                    <nested:text property="quantityCancelled" styleClass="valuetxfield" size="10" onblur="javascript:calculateTotal()" maxlength="9" disabled="<%=enableOrDisable%>" onchange="<%=cancelledString%>" onkeypress="javascript:numericFieldKeyPress( this )"/>
                                    </CENTER>
								</TD>

								<TD WIDTH="10%" ALIGN="CENTER" BGCOLOR="#DEE1E2">
									<CENTER>
									<P><nested:text property="unitCost" styleClass="valuetxfield" maxlength="15" size="22" onblur="javascript:calculateTotal()" disabled="<%=enableOrDisable%>" onkeypress="javascript:amountFieldKeyPress( this )"/>
                                    </CENTER>
								</TD>

								<TD WIDTH="10%" ALIGN="CENTER" BGCOLOR="#DEE1E2">
									<CENTER>
									<P><nested:text property="extendedCost" styleClass="valuetxfield" maxlength="17" size="22" onchange="javascript:changeExtendedCost();" disabled="<%=enableOrDisable%>" onkeypress="javascript:amountFieldKeyPress( this )"/>
                                    </CENTER>
								</TD>

                                <TD WIDTH="10%" ALIGN="CENTER" BGCOLOR="#DEE1E2">
									<CENTER>
									<P>
                                    <nested:hidden property="poLineItemStatusLabel" />
                                    <nested:select property="poLineItemStatus" styleClass="txfield" disabled="true" >
                                       <html:options collection = "poLineItemStatusList" property="value" labelProperty="label"/>
                                    </nested:select>
                                    </CENTER>
                                    <!-- Added for Tax Calculation -->
                                    <nested:hidden property="purchaseTaxOption" />
                                    <nested:hidden property="purchaseItemTaxScheduleId" />
                                    <nested:hidden property="purchaseSiteTaxScheduleId" />
                                    <nested:hidden property="taxAmount" />
                                    <nested:hidden property="bkOutTaxAmount" />
                                    <nested:hidden property="bkOutTradeDiscountTaxAmount" />

								</TD>
								<TD  WIDTH="10%" ALIGN="CENTER" BGCOLOR="#DEE1E2">
									<CENTER>
									<P>
									<% String checkString = "javascript:changeStatus(" + i + ",this)" ; %>
									<nested:checkbox property="cancel" styleClass="txfield" onclick="<%=checkString%>" />

                                    </CENTER>
								</TD>
							</TR>
                            <% i++;%>
                            </nested:iterate>
                            <TR>
                                <TD width="20%" colspan="8">&nbsp;</TD>
                                <TD WIDTH="20%">&nbsp;</TD>
                                <TD WIDTH="12%">&nbsp;</TD>
                                <TD WIDTH="26%">&nbsp;</TD>
                                <TD WIDTH="8%">&nbsp;</TD>
                            </TR>
                            <TR>
                                    <TD WIDTH="20%" colspan="8">&nbsp;</TD>
                                    <TD WIDTH="26%" ALIGN="RIGHT">Subtotal:&nbsp;$</TD>
                                    <TD WIDTH="8%"><nested:text property="subTotal" styleClass="valuetxfield" maxlength="17" size="22" disabled = "true"/></TD>
                                    <TD WIDTH="14%">&nbsp;</TD>
                                    <TD WIDTH="14%">&nbsp;</TD>
                            </TR>
                            <TR>
                                <!-- Commented on 11th Feb 04 -->
                                <TD width="20%" colspan="8">&nbsp;</TD>
                                <!--TD WIDTH="23%" HEIGHT="34" ALIGN="RIGHT">Remaining PO Subtotal:&nbsp;&nbsp;</TD>
                                <TD WIDTH="21%" HEIGHT="34">
                                    <!--nested:text property="remainingPoSubTotal" styleClass="valuetxField" size="10" disabled="true"/>
                                </TD-->
                                <TD WIDTH="26%" ALIGN="RIGHT" >Trade Discount:&nbsp;$</TD>
                                <TD WIDTH="8%" ><nested:text property="tradeDiscount" styleClass="valuetxfield" maxlength="15" size="22" onblur="javascript:calculateTotal()" disabled="<%=enableOrDisable%>" onkeypress="javascript:amountFieldKeyPress( this )"/></TD>
                                <TD WIDTH="14%">&nbsp;</TD>
                                <TD WIDTH="14%" >&nbsp;</TD>
                            </TR>
                            <TR>
                                <!-- Commented on 11th Feb 04 -->
                                <!--TD WIDTH="23%" ALIGN="RIGHT">Purchase Addr Tax Schedule:&nbsp;&nbsp;</TD-->
                                <TD width="20%" colspan="8">Comment:&nbsp;</TD>

                                <!--TD WIDTH="21%">
                                    <!--nested:select property="purchaseAddressTaxScheduleId" styleClass="txfield" >
                                        <!--html:options collection = "taxScheduleList" property="value" labelProperty="label"/>
                                    <!--/nested:select>
                                </TD-->


                                <TD WIDTH="26%" ALIGN="RIGHT">Freight:&nbsp;$</TD>
                                <TD WIDTH="8%"><nested:text property="freight" styleClass="valuetxfield" maxlength="15" size="22" onblur="javascript:calculateTotal()" disabled="<%=enableOrDisable%>" onkeypress="javascript:amountFieldKeyPress( this )"/></TD>

                                <TD WIDTH="14%">&nbsp;<!--chiptrack:restrictedLink functionality="<%//=Functionality.PURCHASE_ORDER%>"
                                        action="<%//=User.USER_ACTION_MODIFY%>"href="javascript:purchaseTaxScheduleEntry()" onmouseover="window.status='Click here to add Purchase Tax Schedule';return true" onmouseout="window.status='';return true">
                                        <IMG SRC="<%//=chipTracContext%>/jsp/includes/images/arrow.gif" WIDTH="14" HEIGHT="15" ALIGN="BOTTOM" BORDER="0">
                                    <!--/chiptrack:restrictedLink-->
                                </TD>
                                <TD WIDTH="14%">&nbsp;</TD>
                            </TR>
                            <TR>


                                <TD WIDTH="40%" COLSPAN="8"  rowspan="2">
                                    <nested:hidden property="commentId"/>
                                    <nested:textarea property="commentDescription" styleClass="txField" rows="4" cols="79" disabled="<%=enableOrDisable%>"  onkeypress="javascript:checkLength(this, 450)"/>
                                </TD>

                                <TD WIDTH="26%" ALIGN="RIGHT">Miscellaneous:&nbsp;$</TD>
                                <TD WIDTH="8%"><nested:text property="miscellaneous" styleClass="valuetxfield" maxlength="15" size="22" onblur="javascript:calculateTotal()" disabled="<%=enableOrDisable%>" onkeypress="javascript:amountFieldKeyPress( this )"/></TD>

                                <TD WIDTH="14%">&nbsp;
                                    <!--chiptrack:restrictedLink functionality="<%//=Functionality.PURCHASE_ORDER%>"
                                        action="<%//=User.USER_ACTION_MODIFY%>"href="javascript:purchaseTaxScheduleEntry()" onmouseover="window.status='Click here to add Purchase Tax Schedule';return true" onmouseout="window.status='';return true">
                                        <IMG SRC="<%//=chipTracContext%>/jsp/includes/images/arrow.gif" WIDTH="14" HEIGHT="15" ALIGN="BOTTOM" BORDER="0">
                                    <!--/chiptrack:restrictedLink-->
                                </TD>
                                <TD WIDTH="14%">&nbsp;</TD>
                            </TR>
                            <TR>
                                <!--TD WIDTH="20%">&nbsp;</TD>
                                <TD WIDTH="20%">&nbsp;</TD-->
                                <TD WIDTH="26%" ALIGN="RIGHT">Tax:&nbsp;$</TD>
                                <TD WIDTH="8%"><nested:text property="tax" styleClass="valuetxfield" maxlength="15" size="22" onblur="javascript:calculateTotal()" disabled="<%=enableOrDisable%>" onkeypress="javascript:amountFieldKeyPress( this )"/></TD>

                                <TD WIDTH="14%">&nbsp;<!--IMG SRC="<%//=chipTracContext%>/jsp/includes/images/arrow.gif" WIDTH="14" HEIGHT="15" ALIGN="BOTTOM" BORDER="0"--></TD>
                                <TD WIDTH="14%">&nbsp;</TD>
                            </TR>
                            <TR>
                                <TD width="20%" colspan="8">&nbsp;</TD>
                                <TD WIDTH="26%" ALIGN="RIGHT">Total:&nbsp;$</TD>
                                <TD WIDTH="8%"><nested:text property="total" styleClass="valuetxfield" size="22" disabled="true"/></TD>
                                <TD WIDTH="14%">&nbsp;</TD>
                                <TD WIDTH="14%">&nbsp;</TD>
                            </TR>
                            <TR>
                                <TD width="20%" colspan="8">&nbsp;</TD>
                                <TD WIDTH="20%">&nbsp;</TD>
                                <TD WIDTH="12%">&nbsp;</TD>
                                <TD WIDTH="26%">&nbsp;</TD>
                                <TD WIDTH="8%">&nbsp;</TD>
                            </TR>
                            <TR>
                                <TD width="20%" colspan="8">&nbsp;
                                </TD>
                                <!--TD WIDTH="21%">&nbsp;</TD-->

                                <TD WIDTH="26%"><P ALIGN="RIGHT">
                                    <chiptrack:restrictedLink functionality="<%=functionalityString%>"
                                        action="<%=User.USER_ACTION_MODIFY%>"href="javascript:addLineItem()" onmouseover="window.status='Click to add a new Line Item';return true" onmouseout="window.status='';return true">
                                        <IMG SRC="<%=chipTracContext%>/jsp/includes/images/addmore.gif" title="Click here to Add Line Item"ALIGN="BOTTOM" BORDER="0" >
                                    </chiptrack:restrictedLink>
                                </TD>
                                <TD WIDTH="8%">
                                    <chiptrack:restrictedLink functionality="<%=functionalityString%>"
                                        action="<%=User.USER_ACTION_MODIFY%>"href="javascript:calculate()" onmouseover="window.status='Click to Calculate';return true" onmouseout="window.status='';return true">
                                        <IMG SRC="<%=chipTracContext%>/jsp/includes/images/calculate.gif" title="Click here to Calculate" ALIGN="BOTTOM" BORDER="0">
                                    </chiptrack:restrictedLink>
                                </TD>
                                <TD WIDTH="12%">&nbsp;</TD>
                                <TD WIDTH="14%">&nbsp;</TD>
                            </TR>
                        </TABLE>
						<BR>
					</TD>
				</TR>
			</TABLE>
           </nested:nest>
           <input type= "hidden" name = "count" value="<%=i%>">
           <input type="hidden" name="actiontype" value="<%= ( request.getAttribute("actiontype") != null ) ?  request.getAttribute("actiontype") : ""%>"><!--added by phani 27/04/04 -->

           </html:form>

					</TD>
				</TR>
				<TR>
					<TD WIDTH="100%">
						<TABLE BORDER="0" WIDTH="100%">
							<TR>
								<TD WIDTH="45%"><P ALIGN="RIGHT">
                                <chiptrack:restrictedLink functionality="<%=functionalityString%>"
                                    action="<%=User.USER_ACTION_MODIFY%>"href="javascript:confirmPO()" onmouseover="window.status='Click here to Save Purchase Order values';return true" onmouseout="window.status='';return true">
                                    <IMG SRC="<%=chipTracContext%>/jsp/includes/images/save.gif" title="Click here to Save Purchase Order" ALIGN="BOTTOM" BORDER="0">
                                </chiptrack:restrictedLink></TD>
                                <TD WIDTH="4%"><%
                                if ( request.getAttribute("actiontype") != null && ((String)request.getAttribute("actiontype")).trim().equalsIgnoreCase("new") )
                                {
                                %>

                                    <A href="<%=chipTracContext%>/jsp/finance/finance_po.jsp" onmouseover="window.status='Click to Cancel and go back ';return true" onmouseout="window.status='';return true" title="Click here Cancel and go back"><IMG SRC="<%=chipTracContext%>/jsp/includes/images/cancel.gif" ALIGN="BOTTOM" BORDER="0"></A><%
                                }
                                else
                                {
                              %><A href="<%=chipTracContext%>/purchaseOrder.do?statusType=Change&action=" onmouseover="window.status='Click to Cancel and go back ';return true" onmouseout="window.status='';return true" title="Click here Cancel and go back" ><IMG SRC="<%=chipTracContext%>/jsp/includes/images/cancel.gif" ALIGN="BOTTOM" BORDER="0"></A><%
                                }
                              %></TD>
								<TD WIDTH="51%"><A href="javascript:reset()" onmouseover="window.status='Click to Reset';return true" onmouseout="window.status='';return true" title="Click here to Reset"><IMG SRC="<%=chipTracContext%>/jsp/includes/images/reset.gif" ALIGN="BOTTOM" BORDER="0"></A></TD>
							</TR>
						</TABLE>
					</TD>
				</TR>
			</TABLE>

<!-- Your Work area ends here -->
		</TD>
		<TD BGCOLOR="white"><IMG SRC="images/spacer.gif" WIDTH="1" HEIGHT="1" ALIGN="BOTTOM" BORDER="0"></TD>
	</TR>
</TBODY></TABLE>

<!-- Footer starts here -->

<%@include file="/jsp/includes/footer.jsp" %>

<!-- footer end here -->
</BODY>
</html:html>